简体   繁体   English

最近PHPMAILER停止发送邮件

[英]Recently PHPMAILER stops sending mail

I have searched a lot but not succeed to find the solution after that i am asking question here. 我已经搜索了很多,但是在我在这里提出问题之后没有成功找到解决方案。

I am using phpmailer on many websites to send mail to admin's email address. 我在许多网站上使用phpmailer将邮件发送到管理员的电子邮件地址。 The following code was working great in past days but recently i got errors in some websites and some websites don't show any error and print that " Mail sent " but i got no email. 以下代码在过去几天中运行良好,但是最近我在某些网站中遇到错误,并且某些网站未显示任何错误并打印出“已发送邮件”,但我没有收到电子邮件。

Here is my code 这是我的代码

$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!
        }

Notice : I am facing this problem on live websites. 注意 :我在直播网站上遇到此问题。 Thanks 谢谢

Synchro's comment is spot-on. Synchro的评论备受关注。 If you have access to the local MTA on the server, you should check its logs, and these will show you 1) whether or not the MTA is receiving the messages that your application is handing-off to it through PHPMailer, and 2) what is happening when the MTA attempts to deliver these messages to the recipients' MX's. 如果您可以访问服务器上的本地MTA,则应检查其日志,这些日志将显示1)MTA是否正在接收应用程序通过PHPMailer传递给它的消息,以及2)什么?当MTA尝试将这些邮件传递到收件人的MX时,就会发生这种情况。

If accessing the local MTA's logs is not possible, then you might want to change your PHP script to use PHPMailer to send outgoing messages through a remote SMTP server that you have credentials for, and preferably one that allows you to access logs showing what happens with messages that are relayed through it. 如果无法访问本地MTA的日志,则可能需要更改PHP脚本,以使用PHPMailer通过具有凭据的远程SMTP服务器发送传出邮件,最好是允许您访问显示以下内容的日志的日志:通过它中继的消息。 See this example of how to use PHPMailer to send through a remote SMTP server (in this case, smtp.gmail.com). 请参阅此示例 ,了解如何使用PHPMailer通过远程SMTP服务器(在本例中为smtp.gmail.com)发送邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM