【问题标题】:PHP mailer SMTP connect() failed. (03/01/2018)PHP 邮件程序 SMTP 连接()失败。 (2018 年 3 月 1 日)
【发布时间】:2018-01-02 17:52:10
【问题描述】:

我在尝试使用 PHPMailer 代码时遇到了一些问题。 此代码在 2017 年 10 月仍然有效,但从 2017 年 12 月至今无效。 我试图找到其他类似的问题,但时间似乎太奇怪了,或者没有帮助。 完成后我没有更改任何内部代码。 但是时间过去了就出现了错误。 我得到了这个错误:

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

当我尝试在故障排除时找到它时,它说它可能是由 localhost 引起的。 这是我的代码:

function mailsend($email,$accepter,$title,$content){
  include_once("../lib/PHPMailer/PHPMailerAutoload.php");   
  $mail = new PHPMailer();                        

  $mail->IsSMTP();                                
  $mail->SMTPAuth = true;                         

  $mail->SMTPSecure = "ssl";                      
  $mail->Host = "smtp.gmail.com";                 
  $mail->Port = 465;                              
  $mail->CharSet = "utf-8";                       
  $mail->Encoding = "base64";
  $mail->WordWrap = 50;                           



  $mail->Username = "myaccount@gmail.com";     
  $mail->Password = "mygmail_account_password";              

  $mail->From = "sender@gmail.com";         
  $mail->FromName = "sender_name";                 

  $mail->Subject = $title; 

  $mail->IsHTML(true);    


  $mailList =       
      array(
          array($email,$accepter)            
      );

  foreach ($mailList as $receiver) {
      $mail->AddAddress($receiver[0], $receiver[1]);  

      $mail->Body = $content;
      if($mail->Send()) {                             
        // echo"<script>alert('success_sended');</script>";
      } else {
        echo $mail->ErrorInfo;
        echo "<br>";
      }
      $mail->ClearAddresses();
  }
}

如果我想更改一些代码以使其再次工作 我可以从哪里开始? 干杯看看。

【问题讨论】:

  • 检查以确保 gmail 没有以某种方式阻止您....也许检查 ErrorInfo,检查您在 gmail 上的帐户....
  • 我建议你试试mailtrap.io。当这工作时。然后你就可以转移到真正的电子邮件服务了。

标签: php smtp gmail phpmailer


【解决方案1】:

我有同样的错误,但使用 Yandex,请尝试添加以下内容:

$mail->SMTPKeepAlive = true;
$mail->Mailer = “smtp”; // 不要更改引号!

在此处查看更多信息https://stackoverflow.com/a/48010266

【讨论】:

    猜你喜欢
    • 2015-07-02
    • 2018-09-03
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    • 2013-09-01
    相关资源
    最近更新 更多