0

I tried several codes to send email. I get "SMTP Error: Could not authenticate". Finally found this code, looked good for me. They say it works. But i still get the same error. I use xampp. Nothing wrong with the username and the password. Any suggestions??

Here's the code,

require_once ("PHPMailer\class.phpmailer.php");
  $Correo = new PHPMailer();
  $Correo->IsSMTP();
  $Correo->SMTPAuth = true;
  $Correo->SMTPSecure = "tls";
  $Correo->Host = "smtp.gmail.com";
  $Correo->Port = 587;
  $Correo->Username = "****@gmail.com";
  $Correo->Password = "****";
  $Correo->SetFrom('****@gmail.com','De Yo');
  $Correo->FromName = "From";
  $Correo->AddAddress("****@hotmail.com");
  $Correo->Subject = "Prueba con PHPMailer";
  $Correo->Body = "<H3>Bienvenido! Esto Funciona!</H3>";
  $Correo->IsHTML (true);
  if (!$Correo->Send())
  {
    echo "Error: $Correo->ErrorInfo";
  }
  else
  {
    echo "Message Sent!";
  }
Niroshan
  • 19
  • 1
  • 5
  • You've based your code on an obsolete example and are using an old version of PHPMailer. [Get the latest](https://github.com/PHPMailer/PHPMailer) and read the docs. – Synchro Jul 20 '16 at 16:01
  • 1
    Possible duplicate of ["SMTP Error: Could not authenticate" in PHPMailer](http://stackoverflow.com/questions/3949824/smtp-error-could-not-authenticate-in-phpmailer) – Synchro Jul 20 '16 at 16:01
  • I'm hesitant to flag this as a duplicate of this [almost identical question](http://stackoverflow.com/questions/3949824/smtp-error-could-not-authenticate-in-phpmailer) - but I'm refraining because the issue was a case mismatch, which your code doesn't suffer from. The non-accepted answers should be helpful there though. – HPierce Jul 20 '16 at 16:01

2 Answers2

0

Try this:

$Correo->Username = "test@gmail.com";
Andy
  • 49,085
  • 60
  • 166
  • 233
Malek Belkahla
  • 510
  • 5
  • 17
0

Check your XAMP mail settings and server logs. Also try 465 port and ssl for secure.

blues911
  • 840
  • 8
  • 9