Question

PHPMailer can not login to smtp gmail

Posted August 5, 2021 148 views
PHPUbuntu 18.04

Please if someone can help me out.
I have a web app working fine on xamp using PHPMailer.
It logs in on gmail and send the mail without any problem.

But when I try the same code on Digital Ocean the smtp fails to login.

I enabled my login on gmail to accept non secure aps and I am not using 2-step verification.

I run the composer on digital ocean server and apparently everything is fine

I verified the port 587 using ufw . It is okay too.

I logged the response on server using :
$mailer->SMTPDebug = SMTP::DEBUG_SERVER;

And the result is below:

I have hidden the ip address with some xxx

2021-08-05 21:58:46 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [68.183.xxx.xxxx]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2021-08-05 21:58:46 CLIENT -> SERVER: AUTH LOGIN
2021-08-05 21:58:46 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2021-08-05 21:58:46 CLIENT -> SERVER: [credentials hidden]
2021-08-05 21:58:46 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2021-08-05 21:58:46 CLIENT -> SERVER: [credentials hidden]
2021-08-05 21:58:46 SERVER -> CLIENT: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt534-5.7.14 gC6q8AVF6VkIfSeXOxjPInPmwRqrlPulbLr63fjfJ7tqG74TVoNCg3hnNmYaAVyzZlNsu534-5.7.14 zJQ90JpRroyE1jegxyI9j28KKiPOt0NHIw5m0Gix8hHC6TlwO9M3BjO7ylcP4RKj>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 b23sm3497724qkl.113 - gsmtp
2021-08-05 21:58:46 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt534-5.7.14 gC6q8AVF6VkIfSeXOxjPInPmwRqrlPulbLr63fjfJ7tqG74TVoNCg3hnNmYaAVyzZlNsu534-5.7.14 zJQ90JpRroyE1jegxyI9j28KKiPOt0NHIw5m0Gix8hHC6TlwO9M3BjO7ylcP4RKj>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 b23sm3497724qkl.113 - gsmtp
SMTP Error: Could not authenticate.

Thank you very much

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there @zeppy,

I could suggest a few things:

  • Make sure that you are using TLS with port 587
  • Make sure that your password is correct
  • And finally enable applications to access your Gmail account:

https://accounts.google.com/b/0/DisplayUnlockCaptcha

On there click on Continue button to complete the step.

If your account uses 2-Step Verification, you may need to create an application-specific password to sign in with your application.

Let me know how it goes.
Regards,
Bobby

  • Thank you very much Bobby. Turns out I have done all of that and none worked.
    But what I did was to use another email I had in other website, using the smtp and phpmailer.
    I gave up google for that.
    Anyway my site is working now and Thank you for your analysis and answer. Have a nice day !