简体   繁体   中英

Using SwiftMailer to send via Gmail suddenly stopped working?

For years our website has used the SwiftMailer plugin to send emails via Gmail. However, seemingly randomly yesterday morning it no longer works for us; we get a message

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [ #0]'

Any ideas what might have caused this? Did Gmail change something with the settings we need to use? Here's what we have currently:

require_once 'path/to/swift-mailer/lib/swift_required.php';
        $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
          ->setPort(465)
          ->setEncryption('ssl')
          ->setUsername('ouremail@gmail.com')
          ->setPassword('ourpassword')
         ;
     $mailer = Swift_Mailer::newInstance($transport);

The problems started around 11AM yesterday morning, and absolutely nothing was changed on our end around that time. Last week I upgraded our PHP version to 5.6.32, but things were working fine since that upgrade until yesterday morning. I even tried reverting back to the old version (only back to 5.6.30), but the error still persisted. I have researched everything on here and elsewhere on the web I could find on this issue and tried everything I could, including trying TLS, changing the port number, using an IP instead of smtp.gmail.com, but nothing has worked. Any ideas?

EDIT: Just discovered the email still works from my local XAMPP setup. This setup is running PHP 5.5.9. So it must be something with our server or domain name provider.

This should be a comment but 1) its a bit long, 2) the comments section is already full of irrelevance.

So you have code which was known to be working but the intended behaviour changed without a change in the code. And you thought to ask why on a site about code problems?

Something has changed outside your code. That's the first place you should be looking.

If gmail had suddenly stopped working or changed its behaviour, I'm fairly sure there would be a lot of people talking about it. Hence the most likely candidate is the infrastucture (including the CAs) supporting your PHP server. But:

1) you've told us nothing about that

2) its off-topic on SO.

I got the same issue that the swift mail just suddenly stop working. The error is

'Connection could not be established with host smtp.gmail.com [ #0]'

. I am using laravel with swift mail to send email through gmail box. The final solution is to download the cert from https://curl.haxx.se/ca/cacert.pem then add "openssl.cafile=path\\cacert-2018-01-17.pem" to php.ini . It's because something related to windows ca library is not updated any more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM