PHP Fatal error: "Swift_TransportException" with the message "Failed to authenticate to the SMTP server

I know that this question was asked before, and I read all the messages there, but I still can’t find a solution.

I have a Windows machine with Wamp installed on it. When I try to send a simple email through a Google SMTP server, everything works fine. Although, when I copy the same script to a Ubuntu 12 machine, this gives me this error:

PHP Fatal error: Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username " xxx@gmail.com " using 2 possible authenticators' in /home/TestMail/SwiftMail/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:171 Stack trace: /home/TestMail/SwiftMail/lib/classes/Swift/Transport/EsmtpTransport.php(289): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport)) /home/TestMail/SwiftMail/lib/classes/Swift/Transport/AbstractSmtpTransport.php(114): Swift_Transport_EsmtpTransport->_doHeloCommand() /home/TestMail/SwiftMail/lib/classes/Swift/Mailer.php(76): Swift_Transport_AbstractSmtpTransport->start() /home/TestMail/testmail.php(73): Swift_Mailer->send(Object(Swift_Message)) thrown in /home/TestMail/SwiftMail/lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 171 

The way I initialize the transport:

 $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl') 

I tried installing telnet on smtp.gmail.com on port 465 and it worked fine, so it should not be a firewall problem.

I have SSL with PHP support. I tried to send two separate letters with and without SSL with another mail server, and everything worked like a charm. This is just Google mail that makes me angry.

Any ideas are welcome here.

All my PHP code is:

 <?php require_once 'SwiftMail/lib/swift_required.php'; // Create the Transport $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl') ->setUsername(' xxx@gmail.com ') ->setPassword('xxx'); // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); $htmlbody = 'some html here'; // Create a message $message = Swift_Message::newInstance('without head') ->setFrom(array('<from email>' => '<some sender>')) ->setTo(array('<to email>' => '<some recepient>')) ->setBody($htmlbody, 'text/html'); // Send the message $result = $mailer->send($message); var_dump($result); ?> 

Thanks!

+4
source share
3 answers

This is an old thread, but my resolution was a little different for the same error. Turns out my Swift configuration is beautiful. The IP address of my server was blocked by Google as suspicious. I was able to clear it by visiting this link, then running the code of my mail program from the server.

http://www.google.com/accounts/DisplayUnlockCaptcha

+23
source

You can also verify that 2-step verification authentication is not enabled. That was for me.

+2
source

Welcome to SO. This is a longer comment than the answer. It’s nice to see that you sent an error message:

PHP Fatal error: throw a Swift_TransportException exception with the message "Authentication failed on the SMTP server with username" xxx@gmail.comm "using 2 possible authenticators in / home / TestMail / SwiftMail / lib / classes / Swift / Transport / Esmtp / AuthHandler.php: 171

Part of this post is actual:

Authentication failed on SMTP server with username " xxx@gmail.comm " using 2 possible authenticators

I would say that this is a typo that you made:

 xxx@gmail.comm ^ 

May happen. Make sure you use the correct credentials. Also, if you find similar questions on the site, this does not mean that they cover your problem.

Hope this helps, otherwise try to provide more error information, for example. is there a log with swiftmailer? Have you double checked your credentials and server configuration? What does a firewall do? And so on and so forth.

+1
source

Source: https://habr.com/ru/post/1437064/


All Articles