我的网络主机有问题,我一直试图拨打支持但尚无答案,所以我在这里试试
我有这个简单的PHP代码,可以将邮件发送到我的Gmail,代码在我的其他托管网站上运行正常,但在www.one.com上,php只显示"您的电子邮件已发送。&#34 ;但是没有发送电子邮件。我已将文件上的权限设置为777,但没有运气。
我有什么办法可以解决这个问题,还是我的网站托管服务器出现问题?
这是我的代码
<?php
$name = "MyName";
$email = "MyName@gmail.com";
$message = "This is a test";
$to = 'Myothermail@gmail.com';
$subject = 'the subject';
$message = 'FROM: '.$name.' Email: '.$email.'Message: '.$message;
$headers = 'From: www.mysite.se' . "\r\n";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $subject, $message, $headers); //This method sends the mail.
echo "<div class='alert alert-success alert_box'>Your email was sent.</div>"; // success message
}
else
{
echo " <div class='alert alert-error alert_box'>Your email address is invalid. Please enter a valid address.</div>";
}
?>
答案 0 :(得分:0)
您的脚本显示您的电子邮件已发送,因为您实际上没有检查任何内容。 mail()如果成功则返回true,否则返回false:
if(mail($to, $subject, $message, $headers)) { //This method sends the mail.
echo "<div class='alert alert-success alert_box'>Your email was sent.</div>"; // success message
} else
{
echo "<div class='alert alert-error alert_box'>Mail send problem.</div>";
}
}
else
{
echo " <div class='alert alert-error alert_box'>Your email address is invalid. Please enter a valid address.</div>";
}
您可以查看日志,还是启用错误报告?