Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP SwiftMailer Failed to authenticate on SMTP server

I am trying to create a test site that handles paypal payment. I am trying to send users an email using PHP SwiftMailer after a successful payment (which is my IPN).

Here is my code for the transport:

        $transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl')
          ->setUsername('[email protected]')
          ->setPassword('xxxx');    

    $mailer = Swift_Mailer::newInstance($transport);

I have tried to use googlemail and another email which is hosted under a shared server and both have problems giving out an error.

Unfortunately, I am getting this usual error:

  Fatal error: Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "[email protected]" using 2 possible authenticators' in /home/xxx/public_html/paypal/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:184 

  Stack trace: 

  #0 /home/xxx/public_html/paypal/lib/classes/Swift/Transport/EsmtpTransport.php(312): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport)) 

  #1 /home/xxx/public_html/paypal/lib/classes/Swift/Transport/AbstractSmtpTransport.php(120): Swift_Transport_EsmtpTransport->_doHeloCommand() 

  #2 /home/xxx/public_html/paypal/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start() 

  #3 /home/xxx/public_html/paypal/ipn.php(113): Swift_Mailer->send(Object(Swift_Message)) 

  #4 /home/mctikudo/public_html/paypal/ipn.php(46): sendMail(Resource id #3, Array) 

  #5 {main} thrown in /home/xxx/public_html/paypal/lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 184

I have done some research and tried several approach in the setting of my transport. But still nothing seems to work. Until I just tried to place my IPN code to another server under another hosting company and surprisingly, it works. Same code from the other one.

This is why I guess there is something in the other server must be set or something.

Are there things that I need to make sure that is enabled on my server to have the SwiftMailer work?

like image 312
Atasha Avatar asked Oct 02 '13 10:10

Atasha


2 Answers

This might be old but somebody might get help through this. I too faced the same problem and received a mail on my gmail account stating that someone is trying to hack your account through an email client or a different site. THen I searched and found that doing below would resolve this issue.

Go to https://accounts.google.com/UnlockCaptcha‎ and unlock your account for access through other media/sites.

UPDATE : 2015

Also, you can try this, Go to https://myaccount.google.com/security#connectedapps At the bottom, towards right there is an option "Allow less secure apps". If it is "OFF", turn it on by sliding the button.

like image 51
roneo Avatar answered Sep 17 '22 16:09

roneo


As already stated this might be old but you can try and allow gmail to send mails through less secure apps.

https://www.google.com/settings/security/lesssecureapps

This made it work for me and I had the same issue.

like image 40
PvPlatten Avatar answered Sep 18 '22 16:09

PvPlatten