-3

I receive this error: SMTP Error: Could not authenticate.

This is the code, i think that everything is ok, the password is ok, the emails are ok, ist in localhost,...

<?php

require './class.phpmailer.php';

$mail = new PHPMailer();

$mail->IsSMTP();

$mail->SMTPDebug  = 0;

$mail->Host       = 'smtp.gmail.com';

$mail->Port       = 587;

$mail->SMTPSecure = 'tls';

$mail->SMTPAuth   = true;

$mail->Username   = "email@gmail.com";

$mail->Password   = "*********";

$mail->SetFrom('email@gmail.com', 'user');

$mail->AddAddress('email2@gmail.com', 'user');

$mail->Subject = 'this is a text email';

$mail->MsgHTML('content');

$mail->AltBody = 'This is a plain-text message body';

if(!$mail->Send()) {
  echo "Error: " . $mail->ErrorInfo;
} else {
  echo "Send!";
}

?>
Oximandias
  • 61
  • 2
  • 6
  • Set `SMTPDebug` to `1` and see if you get any additional information. – Andrew May 15 '14 at 16:30
  • 2
    **Before you post a question asking “How do I solve this error?" do a search in the search box for the actual error message.** There you will probably find other questions from people who have had the exact same problem, and then you can learn how they solved it. – Andy Lester May 15 '14 at 16:59

1 Answers1

1

Set SMTPDebug to 2 and see what you get but it seems like you're connecting and quite literally not able to authenticate with google's smtp server, if so your username or password is indeed wrong or being blocked (sometimes gmail will block logins from connections it's never seen before until you login and assure it everything's fine).

JasonSec
  • 614
  • 5
  • 12