Jump to content

Email address change with ID


timmah1

Recommended Posts

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.

Link to comment
Share on other sites

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); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.