3

The email address and password is definitely correct. The script was working until yesterday. Now we receive the following error:

Mailer Error: SMTP connect() failed.

We can login to the Google email address. I can send emails via SMTP in Outlook. We have Google Apps Free Edition, so it is not possible to contact Google.

Does anyone have any ideas as to why the connection has just stopped working? Thank you.

  mail->SMTPDebug  = 2;
      $mail->IsSMTP(true); // enable SMTP
      $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
      $mail->SMTPAuth = true;  // authentication enabled
      $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
      $mail->Host = 'smtp.gmail.com';
      $mail->Port = 465;               // set the SMTP port for the GMAIL server
      $mail->Username   = $Username; // SMTP account username
      $mail->Password   = $Password;

      $doc_dir = 'pdf/';
      $mail->From = $From;
      $mail->FromName = $FromName;
      $mail->addAddress($email);

      $mail->WordWrap = 50; 
      $mail->addAttachment($doc_dir.$FileName);       
      $mail->isHTML(true);  
      $mail->Subject = 'Your '.$warehouse_name.' Order Has Shipped';
      $mail->Body    = $Message;
      $mail->AltBody = 'Racquet Depot UK';

      if(!$mail->send()) {

       echo 'Message could not be sent.';
              echo 'Mailer Error: ' . $mail->ErrorInfo;
         exit;
      };
VolkerK
  • 95,432
  • 20
  • 163
  • 226
Jack
  • 96
  • 12
  • Firstly, see related question http://stackoverflow.com/questions/18496650/smtp-connect-failed-message-was-not-sent-mailer-error-smtp-connect-failed. Also, you can found some answers in http://www.finalwebsites.com/forums/topic/php-mailer-authentification-problem. – Mihai8 Jul 05 '15 at 11:30
  • This question has literally hundreds of duplicates, all with very predictable answers. The first place you should look is the [PHPMailer troubleshooting documentation](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting) as it's faster and more accurate than anything you will find on here. – Synchro Jul 06 '15 at 07:17
  • You should also use [an up to date example](https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps) to base your code on (yours is years out of date) and make sure you're using the latest PHPMailer. – Synchro Jul 06 '15 at 07:19

1 Answers1

0

The host had made an SMTP restriction which caused the issue. Otherwise, the code is correct.

Jack
  • 96
  • 12