【发布时间】:2016-02-11 05:55:05
【问题描述】:
我已经搜索了很多但没有成功找到解决方案,之后我在这里提出问题。
我在许多网站上使用 phpmailer 将邮件发送到管理员的电子邮件地址。以下代码在过去几天运行良好,但最近我在某些网站中遇到错误,有些网站没有显示任何错误并打印“已发送邮件”但我没有收到电子邮件。
这是我的代码
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->Host = "localhost"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->AddAddress('ADMIN_ADDRESS');
$mail->SetFrom($_REQUEST['email'], $_REQUEST['lname'] . ', ' . $_REQUEST['fname']);
$mail->Subject = 'Contact Form';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($body);
$mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
注意:我在实时网站上遇到了这个问题。谢谢
【问题讨论】:
-
您在此处使用默认的“邮件”传输,因此最可能的解释是您的本地邮件服务器有问题 - 检查您的邮件服务器日志。
-
谢谢,我会检查服务器日志
标签: php html email smtp phpmailer