<?php$EmailFrom = Trim(stripslashes($_POST['Email']));$EmailTo = Trim(stripslashes($_POST['Recipient']));$EmailCc = \"MYEMAIL@gmail.com\";$Subject = \"TEST Contact\";$Name = Trim(stripslashes($_POST['Name'])); $Tel = Trim(stripslashes($_POST['Tel'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); // validation$validationOK=true;if (!$validationOK) { print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=error.htm\\">\"; exit;}// prepare email body text$Body = \"\";$Body .= \"Name: \";$Body .= $Name;$Body .= \"\n\";$Body .= \"Tel: \";$Body .= $Tel;$Body .= \"\n\";$Body .= \"Email: \";$Body .= $Email;$Body .= \"\n\";$Body .= \"Message: \";$Body .= $Message;$Body .= \"\n\";// send email $success = mail($EmailTo, $Subject, $Body, \"From: <$EmailFrom>\");// redirect to success page if ($success){ print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=contactthanks.php\\">\";}else{ print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=error.htm\\">\";}?>
$EmailCc = \"MYEMAIL@gmail.com\";
$EmailTo = \"UREMAIL@EMAIL.COM, \".Trim(stripslashes($_POST['Recipient']));
$success = mail($EmailTo, $Subject, $Body, \"From: <$EmailFrom>\");// redirect to success pageif ($success){ //copy to someone else mail(newaddress@newaddress.com, $Subject, $Body, \"From: <$EmailFrom>\"); print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=contactthanks.php\\">\";}
<?php$header = \"From: $EmailFrom\r\n\";$header .= \"CC: otheremail@*website*.com\r\n\"; $header .= \"BCC: yetanotheremail@*website*.com\r\n\"; // send email $success = mail($EmailTo, $Subject, $Body, $header);?>
<?php$header = \"From: server@thisdomain.com\r\n\";$header .= \"Replyto: $EmailFrom\r\n\";$header .= \"CC: otheremail@*website*.com\r\n\";$header .= \"BCC: yetanotheremail@*website*.com\r\n\";// send email$success = mail($EmailTo, $Subject, $Body, $header);?>
I took the simpleform from the site and have modified it a bit to allow the user to choose who receives the email.
I also wanted to add a 'CC' if possible.
Here is the code:
I added this little snippet as i thought it may send the second email, but it didn't work.
Maybe I should just modify the '$EmailTo' variable, but i'm not too proficient in php.
Enjoy,
It's good practice to always send the email from the domain that your server is on and use a replyto instead.