How to use PHPMailer, after 30 May 2022 when "Less secure app" is no longer an option?

Viewed 6931

I have been using PHPMailer for a long time to send emails using Google credentials (login and password) by enabling the "Less secure app" option in the Google settings.

As Google is notifying that after 30th May 2022, Google will not allow sending emails using the "Less secure app".

Less secure apps & your Google Account

enter image description here

Is there any other way to send emails using Gmail SMTP from PHPMailer without the "Less secure app" feature?

2 Answers

What you need to do is switch to XOAUTH2 or to the Gmail API again using Oauth2.

$mail->oauthUserEmail = "[Redacted]@gmail.com";
$mail->oauthClientId = "[Redacted]";
$mail->oauthClientSecret = "[Redacted]";
$mail->oauthRefreshToken = "[Redacted]";

You can't send email with out the users permission. The owner of the gmail account you are trying to send mails from will need to authorize the app once if you store the refresh token you should be able to use it without any issues.

Remember you will need to go though the application verification process with google. As you will be using a sensitive scope.

Using their login and password is no longer an option.

This ways work for me, you can try this :

  1. First go to your google account management and go to security.
  2. Make sure your 2-step verification are enabled.
  3. Then go to app password.
  4. Select other in the select app dropdown menu, and named whatever you like.
  5. And click generate, google will give you a password. make sure you copy it and save it somewhere else.
  6. instead using your real google account password in PHPMailer setting, use the password you just generate.
Related