timmah1 Posted April 14, 2008 Share Posted April 14, 2008 I'm trying to have one contact form for every aspect of the site, but I need the form to go to different people depending on the id that is passed. The subject works find with a variable being passed, but the $to part don't. Here is what I'm 'trying' if($_POST['id'] == "NN"){ $to='[email protected]'; $subject = '$_POST[subject]'; $headers = "From: Autisim Summer Camp Information\r\nX-Mailer: Autisim Summer Camp"; $body = "$_POST[first] $_POST[last] from $_POST[email] is requesting information about $_POST[subject]. In addition, they have posted this message: $_POST[message]"; mail($to, $subject, $body, $headers); } else if($_POST['id'] == "NI"){ $to='[email protected]'; $subject = '$_POST[subject]'; $headers = "From: Autisim Summer Camp Information\r\nX-Mailer: Autisim Summer Camp"; $body = "$_POST[first] $_POST[last] from $_POST[email] is requesting information about $_POST[subject]. In addition, they have posted this message: $_POST[message]"; mail($to, $subject, $body, $headers); } This doesn't work. Can anybody help me out? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/101131-email-address-change-with-id/ Share on other sites More sharing options...
hitman6003 Posted April 15, 2008 Share Posted April 15, 2008 What doesn't work about it? Is there an error generated? If so, what is it? Have you tried troubleshooting? What have you done to troubleshoot? Have you verified the value of $_POST['id']? Why are you duplicating all of the code in two places? Employ the DRY method (http://en.wikipedia.org/wiki/DRY) to simplify. if($_POST['id'] == "NN") { $to='[email protected]'; } else if($_POST['id'] == "NI") { $to='[email protected]'; } echo "This message will be sent to " . $to . " because id is equal to " . $_POST['id']; $subject = $_POST[subject]; $headers = "From: Autisim Summer Camp Information\r\nX-Mailer: Autisim Summer Camp"; $body = "$_POST[first] $_POST[last] from $_POST[email] is requesting information about $_POST[subject]. In addition, they have posted this message: $_POST[message]"; mail($to, $subject, $body, $headers); Link to comment https://forums.phpfreaks.com/topic/101131-email-address-change-with-id/#findComment-517214 Share on other sites More sharing options...
timmah1 Posted April 15, 2008 Author Share Posted April 15, 2008 I'm sorry that I didn't clarify myself more. But obviously I explained it enough because your answer fixed everything. Thank you for your help. Link to comment https://forums.phpfreaks.com/topic/101131-email-address-change-with-id/#findComment-517232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.