dongluan1743 2018-01-02 17:52
浏览 53

PHP邮件程序SMTP connect()失败。 (2018年3月1日)

I got some problem when I try to use PHPMailer code. This code still works on Oct/2017 but not work since Dec/2017 to now. I tried to find other similar question but time seems too odd, or it doesn't help. I didn't change any code inside since I finished. but error appeared when time passed. And I got this error:

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

when I try to find it on troubleshotting, it says it might cause by localhost. Here is my code:

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();
  }
}

If I want to change some code to make it work again where can I start? Cheers for taking a look.

  • 写回答

1条回答 默认 最新

  • donglu5728 2018-01-03 20:01
    关注

    I had the same Error but with Yandex,try adding the following:

    $mail->SMTPKeepAlive = true;
    $mail->Mailer = “smtp”; // don't change the quotes!

    See more here https://stackoverflow.com/a/48010266

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀