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 Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/ 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 Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561074 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! Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561075 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? Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561082 Share on other sites More sharing options...
jesushax Posted June 9, 2008 Share Posted June 9, 2008 takeaway the double == Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561084 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 Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561086 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: [email protected]\r\[email protected] 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 Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561089 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 Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561094 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? Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561097 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 Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561101 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 Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561106 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? Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561112 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?? Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561116 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 Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561139 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 Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561153 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']); Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561181 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 Link to comment https://forums.phpfreaks.com/topic/109389-placing-ifs-with-a-variable/#findComment-561204 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.