即使mail()函数正常运行,我也没有在我的Gmail邮箱中收到邮件。我已经配置了php.ini文件和sendmail.ini文件。 我试图使用各种方式使其工作。 尽管可以成功显示该邮件已发送,但实际上并未发送。
<?php
$errors = '';
$myemail = 'abc@gmail.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";
$result = mail($to,$email_subject,$email_body,$headers);
if(isset($result)){
echo "Sent Mail";
}
else{
echo 'mail cant be sent';
var_dump($result);
}
}
?>