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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划