Reputation: 3
PHPMailer works at localhost phpmyadmin, but not work after I deployed on heroku, It seems that PHPMailer has authenticate problem on heroku. Anyone knows the reason?
$to = '[email protected]';
$subject = 'Aliens Abducted Me - Abduction Report';
$msg = "$name was abducted $when_it_happened and was gone for $how_long.\n" .
"Number of aliens: $how_many\n" .
"Alien description: $alien_description\n" .
"What they did: $what_they_did\n" .
"Fang spotted: $fang_spotted\n" .
"Other comments: $other";
$mail = new PHPMailer();
$mail-> SMTPDebug=2;
$mail -> isSMTP();
$mail -> Host='smtp.gmail.com';
$mail -> SMTPAuth =true;
$mail -> Username='[email protected]';
$mail -> Password= 'correct password';
$mail -> SMTPSecure ='tls';
$mail -> Port =587;
$mail -> setFrom($to);
$mail -> addAddress($to);
$mail -> addReplyTo($to);
$mail -> Subject=$subject;
$mail -> Body=$msg;
$mail -> send();
And this is the error I got
2018-01-29 23:50:50 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP y29sm10762113qtk.47 - gsmtp
2018-01-29 23:50:50 CLIENT -> SERVER: EHLO immense-bayou-46149.herokuapp.com
2018-01-29 23:50:50 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [54.158.107.41]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2018-01-29 23:50:50 CLIENT -> SERVER: STARTTLS
2018-01-29 23:50:50 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-01-29 23:50:50 CLIENT -> SERVER: EHLO immense-bayou-46149.herokuapp.com
2018-01-29 23:50:50 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [54.158.107.41]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2018-01-29 23:50:50 CLIENT -> SERVER: AUTH LOGIN
2018-01-29 23:50:50 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2018-01-29 23:50:50 CLIENT -> SERVER: <credentials hidden>
2018-01-29 23:50:50 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2018-01-29 23:50:50 CLIENT -> SERVER: <credentials hidden>
2018-01-29 23:50:50 SERVER -> CLIENT: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbty534-5.7.14 OxYqa_vgUvCRSPkrtCYvPqBkjM-c0OPhKwgtdEA-4Du9zmkqJK4-wc6EnlEwORPnhd5VeD534-5.7.14 nGYK31F2CT1owGvIlWvSuyfXZ7YYqHnRK7y8HCRQR3OmDf9VC1YbXjy2lfanNuSZq1NLMB534-5.7.14 X1F27an8Z_tB7u9-an0ree4tmC6TUr6TuUnmxaybqouLZDiTGy1coPfbeD4JLr0CL59SSY534-5.7.14 U-Qigx5DTQIaZ8H0onzz3s9E-sLpg> Please log in via your web browser and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 y29sm10762113qtk.47 - gsmtp
2018-01-29 23:50:50 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbty534-5.7.14 OxYqa_vgUvCRSPkrtCYvPqBkjM-c0OPhKwgtdEA-4Du9zmkqJK4-wc6EnlEwORPnhd5VeD534-5.7.14 nGYK31F2CT1owGvIlWvSuyfXZ7YYqHnRK7y8HCRQR3OmDf9VC1YbXjy2lfanNuSZq1NLMB534-5.7.14 X1F27an8Z_tB7u9-an0ree4tmC6TUr6TuUnmxaybqouLZDiTGy1coPfbeD4JLr0CL59SSY534-5.7.14 U-Qigx5DTQIaZ8H0onzz3s9E-sLpg> Please log in via your web browser and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 y29sm10762113qtk.47 - gsmtp
SMTP Error: Could not authenticate.
2018-01-29 23:50:50 CLIENT -> SERVER: QUIT
2018-01-29 23:50:50 SERVER -> CLIENT: 221 2.0.0 closing connection y29sm10762113qtk.47 - gsmtp
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Upvotes: 0
Views: 1330
Reputation: 136918
I'm not sure why Gmail isn't working, but I strongly urge you to use a more appropriate service.
Heroku has good support for sending mail using a variety of production-grade email services. I've personally used SendGrid and been quite happy with it.
You can use environment variables to configure your mailing settings, e.g. to point your development machine at a tool like MailCatcher and point your production Heroku machine to SendGrid.
Upvotes: 1