Can't Send Email through PHP on localhost using Gmail account


On 30 May 2022 Google changed "Less secure apps" settings and it’s no longer available.

Less secure apps & your Google Account

To help keep your account secure, from May 30, 2022, ​​Google no longer supports the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.

Due to which I’m not able to send Email on localhost using PHP.

Is there any other way to do this ?


I am going to assume you are connecting to Gmail via the smtp server.

If you are currently using the actual password for the gmail account you are connecting to. The the best thing to do would be to try creating an apps password and using that.

Sign in with App Passwords

$mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
$mail->isSMTP();                                            //Send using SMTP
$mail->Host       = '';                     //Set the SMTP server to send through
$mail->SMTPAuth   = true;                                   //Enable SMTP authentication
$mail->Username   = '[email protected]';                     //SMTP username
$mail->Password   = 'APPsPassword';                               //New apps password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
$mail->Port       = 465;                      

Another option would be to switch to Xoauth or switching to the Gmail api again using Oauth2.

$mail->oauthUserEmail = "[Redacted]";
$mail->oauthClientId = "[Redacted]";
$mail->oauthClientSecret = "[Redacted]";
$mail->oauthRefreshToken = "[Redacted]";

Answered By – DaImTo

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published