不确定为什么我一直在PHP电子邮件表单上收到语法错误消息

时间:2017-07-18 15:07:01

标签: php forms email

我几天来一直遇到php电子邮件表单的语法错误,不知道发生了什么。我编写了自己的代码,甚至使用了3种不同的预编写代码,并且我一直看到相同的语法错误,该行告诉它需要将表单详细信息发送到哪个电子邮件。

为了发布,我已经更改了电子邮件,因为不显示我自己的电子邮件

该行是

$myemail = "usersemail@testemail.com";//<-----Put Your email address here.

我已经尝试过,gmail,hotmail,雅虎,甚至为了它甚至aol电子邮件。我有“”和“”,并且在该行上保持语法错误。我不知道它是什么。

以下是我目前使用的完整代码

<?php

$errors = '';

$myemail = "usersemail@rocketmail.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: contact-form-thank-you.html');

}


?>

0 个答案:

没有答案