Question

PHPMailer can not login to smtp gmail

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


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
August 9, 2021
Accepted 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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more