Php – “SMTP Error: Could not authenticate” in PHPMailer


I'm using PHPMailer in a Simple Script For Send Email's Through Gmail, and I'm getting an "Unknown Error" (At least for me!):

SMTP Error: Could not authenticate.
Error: SMTP Error: Could not

SMTP server error: 5.7.1 Username and
Password not accepted. Learn more at
535 5.7.1

I've read about Configure OpenSSL For SSL/TLS Connections, and I did it. Apache And PHP Are properly-Configured (With OpenSSL extension Running in PHP and mod_ssl running in Apache 2.2.16).

This is The PHP Script:

  require_once ("PHPMailer\class.phpmailer.php");
  $Correo = new PHPMailer();
  $Correo->SMTPAuth = true;
  $Correo->SMTPSecure = "tls";
  $Correo->Host = "";
  $Correo->Port = 587;
  $Correo->UserName = "";
  $Correo->Password = "gmailpassword";
  $Correo->SetFrom('','De Yo');
  $Correo->FromName = "From";
  $Correo->Subject = "Prueba con PHPMailer";
  $Correo->Body = "<H3>Bienvenido! Esto Funciona!</H3>";
  $Correo->IsHTML (true);
  if (!$Correo->Send())
    echo "Error: $Correo->ErrorInfo";
    echo "Message Sent!";

The Username and Password are OK, And I tried in Thunderbird, without any problem.
I've also Used SSL Authentication and Port 465, getting the same Error.

Best Solution

I encountered this problem. To get it working, I had to go to -> "Sign-in & security" -> "Apps with account access", and turn "Allow less secure apps" to "ON" (near the bottom of the page).

Alternatively you can follow this direct link to these settings

enter image description here

Related Question