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='your@email.com'; $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='me@email.com'; $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. Quote Link to comment 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='your@email.com'; } else if($_POST['id'] == "NI") { $to='me@email.com'; } 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); Quote Link to comment 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. 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.