Pergunta

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!";
}

?>
Foi útil?

Solução

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).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top