Reputation: 499
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?
Upvotes: 5
Views: 20870
Reputation: 23
i know im too late but i was frustrated with this error and i fixed it thanks to all these answers, i hope this helps.
This worked with a website that is hosted on AWS Elastic BeansTalk. add this in your email.php or whatever
require_once 'files-needed/vendor/autoload.php';
//to send emails to our users
//google does not recognize this so we must change google settings
//(Allow less secure apps) Turned on
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 587, 'tls'))
->setUsername(EMAIL)
->setPassword(PASSWORD);
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
And thanks to roneo i did this
Go to https://accounts.google.com/UnlockCaptcha and unlock your account for access through other media/sites.
Step 1:(important!!) Just make sure that when you access this link
you are signed in from the same email from the php code, because i thought i was but when i entered https://accounts.google.com/ turns out it was another email.
Step 2: i followed the instructions in the page, then immediately went to my website and sent an email, and Finally.. it WORKED!!
Upvotes: 0
Reputation: 1257
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.
Upvotes: 18
Reputation: 1146
I know this is old but hopefully this points someone in the right direction. I had this same problem when using a Mandrill and Swiftmailer combination.
My issue was that the server was stopping SMTP messages from port 587, and this was in relation to the FKA SMTP Tweak settings which were on my server.
So if you have Cpanel and can access WHM, try looking at your mail settings under tweaks to see if outgoing SMTP mail is restricted. Other option is that maybe your server considers a port as suspicious. Try changing the port, I found that my hosting company had a list of suitable ports.
Upvotes: 3
Reputation: 560
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.
Upvotes: 5