0

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.

William Hu
  • 13
  • 5
  • check to make sure that gmail didn't block you somehow....perhaps check the ErrorInfo, check your account on gmail.... – C. Geek Jan 02 '18 at 18:15
  • I suggest you try out `mailtrap.io`. When this is working. Then you can move to real email service. – Shiro Jan 03 '18 at 06:53

1 Answers1

1

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