dmccabe Posted June 9, 2008 Share Posted June 9, 2008 Can anyone tell me how I can do this and make it work? $message = "Username: $first_name \n Surname: $surname \n Company: $company \n Location/Dept: $location \n Job Title: $job_title \n Start Date: $start_date \n Software Required: " . if ($prohire == "1") { "Prohire" } ." || " . if ($prolease == "1") { "Prolease" } ." || " . if ($proclaim == "1") { "Proclaim" } ." || " . if ($prolease == "1") { "Prolease" } ." || " . if ($sage == "1") { "Sage" } ." || " . if ($email == "1") { "email" } ." \n " . if ($other == "1") { "Other Software: $other_software \n" } ." " . if ($internet == "whitelist") { "Internet: Whitelist Only \n" } else { "Internet: Full - Reason: $internet_reason \n" } ." " . if (isset($mailing_lists)) { "Mailing Lists: $mailing_lists \n" } . " " . if (isset($other_reqs)) { "Mailing Lists: $other_reqs \n" } . " =============================================== \n Requested By: $requested_by on $requested_date"; so that it is all part of the $message variable, but with differing results based on the results of the if's Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 9, 2008 Share Posted June 9, 2008 you can use a if statement to set a variable but cant have if staments within them if you do $message = "Username: $first_name \n Surname: $surname \n Company: $company \n Location/Dept: $location \n Job Title: $job_title \n Start Date: $start_date \n Software Required: " if (statment here ) { $message = $message."value if true" } $message = $message."=============================================== \n Requested By: $requested_by on $requested_date";" that will carry the begingin of your statment then you can add yoru true values home that helps Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 9, 2008 Author Share Posted June 9, 2008 ah hah excellent thank you very much, I didnt think the way I had tried to do it would work, but hey if you dont try you dont know eh! Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 9, 2008 Author Share Posted June 9, 2008 ok I gave it a go your way, but am still doing something wrong: $message = "Username: $first_name \n Surname: $surname \n Company: $company \n Location/Dept: $location \n Job Title: $job_title \n Start Date: $start_date \n Software Required: "; if ($prohire == "1") { $message == $message."Prohire - "; } if ($prolease == "1") { $message == $message."Prolease - "; } if ($proclaim == "1") { $message == $message."Proclaim - "; } if ($prolease == "1") { $message == $message."Prolease - "; } if ($sage == "1") { $message == $message."Sage - "; } if ($email == "1") { $message == $message."E-mail - \n"; } if ($other == "1") { $message == $message."Other Software: $other_software \n"; } if ($internet == "whitelist") { $message == $message."Internet: Whitelist Only \n"; } elseif ($internet == "full") { $message == $message."Internet: Full - Reason: $internet_reason \n"; } if (isset($mailing_lists)) { $message == $message."Mailing Lists: $mailing_lists \n"; } if (isset($other_reqs)) { $message == $message."Mailing Lists: $other_reqs \n"; } $message == $message."=============================================== \n Requested By: $requested_by on $requested_date"; All works but the $message stops as "Software Required:" even though I know $prohire = 1 Any thoughts? Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 9, 2008 Share Posted June 9, 2008 takeaway the double == Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 9, 2008 Share Posted June 9, 2008 Replace this: <?php if ($prohire == "1") { $message == $message."Prohire - "; } if ($prolease == "1") { $message == $message."Prolease - "; } if ($proclaim == "1") { $message == $message."Proclaim - "; } if ($prolease == "1") { $message == $message."Prolease - "; } if ($sage == "1") { $message == $message."Sage - "; } if ($email == "1") { $message == $message."E-mail - \n"; } if ($other == "1") { $message == $message."Other Software: $other_software \n"; } if ($internet == "whitelist") { $message == $message."Internet: Whitelist Only \n"; } elseif ($internet == "full") { $message == $message."Internet: Full - Reason: $internet_reason \n"; } if (isset($mailing_lists)) { $message == $message."Mailing Lists: $mailing_lists \n"; } if (isset($other_reqs)) { $message == $message."Mailing Lists: $other_reqs \n"; } $message == $message."=============================================== \n ?> with <?php if ($prohire == "1") { $message .= "Prohire - "; } if ($prolease == "1") { $message .= "Prolease - "; } if ($proclaim == "1") { $message .= "Proclaim - "; } if ($prolease == "1") { $message .= "Prolease - "; } if ($sage == "1") { $message .= "Sage - "; } if ($email == "1") { $message .= "E-mail - \n"; } if ($other == "1") { $message .= "Other Software: $other_software \n"; } if ($internet == "whitelist") { $message .= "Internet: Whitelist Only \n"; } elseif ($internet == "full") { $message .= "Internet: Full - Reason: $internet_reason \n"; } if (isset($mailing_lists)) { $message .= "Mailing Lists: $mailing_lists \n"; } if (isset($other_reqs)) { $message .= "Mailing Lists: $other_reqs \n"; } $message .= "===============================================\nRequested By: $requested_by on $requested_date"; ?> The ".=" is a shorthand for $x = $x . "xyz" Ken Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 9, 2008 Author Share Posted June 9, 2008 thanks again jesushax One last thing. i have a text area used for entering mailing list names, they will put multiple items in here on different lines. when it send the email I get this: Mailing Lists: hostaff@xyz.com\r\nadmin@xyz.com How do I make it put them on seperate lines? This is the code: if (isset($mailing_lists)) { $message = $message."Mailing Lists: $mailing_lists \n"; } Edit: Thanks ken for tip too Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 9, 2008 Share Posted June 9, 2008 No Problem try using a html break <br /> instead of \r\ Cheers Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 9, 2008 Author Share Posted June 9, 2008 Unfortunately I can't use <br /> as it is sending an email to our helpdesk system which cannot accept html mails ;/ Any other way? Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 9, 2008 Share Posted June 9, 2008 erm im not sure mate, someone here will know though, just hang about for a response Quote Link to comment Share on other sites More sharing options...
craygo Posted June 9, 2008 Share Posted June 9, 2008 \r is used for apple systems, I think, try using \n instead. it will be correct when you send it out but will not look correct if you are trying to echo it our to the browser. If you want to do a test as to what it will look like then you can use nl2br() to send it to the browser as it would look in the e-mail. Ray Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 9, 2008 Author Share Posted June 9, 2008 hehehe thats the thing I have specified for it to use \r anywhere. I have used \n's all the way through it, but it appears that if someone page an enter in the text area that is converting it to \r, but why? Quote Link to comment Share on other sites More sharing options...
craygo Posted June 9, 2008 Share Posted June 9, 2008 what are the specs for you web server?? Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 9, 2008 Author Share Posted June 9, 2008 it is a windows 2000 server running WAMP Quote Link to comment Share on other sites More sharing options...
craygo Posted June 9, 2008 Share Posted June 9, 2008 What do you have for the code for $mailing_lists. Show the code where it is being set. Ray Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 9, 2008 Author Share Posted June 9, 2008 Thanks Craygo: $mailing_lists = mysql_real_escape_string($_POST['mailing_lists']); Quote Link to comment Share on other sites More sharing options...
craygo Posted June 9, 2008 Share Posted June 9, 2008 OK. So the mailing list names are in a text area?? my textarea does the same. you can use this to get just \n I got it from the php site, just changed it a little $mlist = mysql_real_escape_string($_POST['mailing_lists']); $order = array('\r\n', '\n', '\r'); $replace = '\n'; // Processes \r\n's first so they aren't converted twice. $mailing_lists = str_replace($order, $replace, $mlist); Ray Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.