Currently I have the code below which sends the contents of the html input field (email) to the welcome@domain.com address. There are two things which I am now struggling with. I have used the following bits of code to no avail -
$to = "welcome@domain.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thankyou.html');
How can I automatically send an email response from welcome@domain.com?
Instead of the page saying 'Thank you for contacting us, we will be in touch very soon' is there a way that they are redirected to domain.com/thankyou.html instead?
This is the rest of the code which seems to be working fine! If there are any suggestions for this though they are always more than welcome!
if(isset($_POST['email'])) {
$email_to = "welcome@domain.com";
$email_subject = "Your spot has been saved!";
function died($error) {
echo "We are very sorry, but there were error(s) found with the form your submitted";
echo "These errors appear below<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors<br /><br />";
die();
}
if(
!isset($_POST['email'])
) {
died("We are sorry, but there appears to be a problem with the form your submitted!");
}
$email_from = $_POST['email'];
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email_from)) {
$error_message .= "The Email Address you entered does not appear to be valid!<br />";
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= 'Email: '.clean_string($email_from)."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?
}
?>