-1

Every time I try i click on send this error appears. I get the message on my email, but the problem is that it takes me to an error page instead of taking me to the page that i have specified.

This is my code:

<?php 
$errors = '';
$myemail = 'info@cherry-ao.com';//<-----Put Your email address here.

if(empty($_POST['name'])  ||  empty($_POST['email']) || empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address))
{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Contact form submission: $name";
    $email_body = "You have received a new message. Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message"; 
    $headers = "From: $myemail\n"; 
    $headers .= "Reply-To: $email_address";
    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: thank_you.html');
} 

echo nl2br($errors);
?>

There are no spaces! Im hosting my website with Hostgator

4

1 回答 1

2

如果您已将一些数据放入屏幕,则无法编写标题。

在向用户输出任何内容之前,标头必须位于代码的顶部

于 2013-10-18T18:29:51.910 回答