PHPMailer XAMPP SMTP身份验证失败


PHPMailer XAMPP SMTP Authentication failed

我试图使用PHPMailer从XAMPP上的本地虚拟主机发送电子邮件,代码如下。我在php.ini中启用了extension=php_openssl.dll,仍然得到下面的错误消息。有人知道为什么吗?

require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "xxx";
$mail->Password = "xxx";
$email = "xxx@gmail.com";
$name = "Test";
$email_from = "xxx@gmail.com";
$name_from = "Test";
$mail->AddAddress($email, $name);
$mail->SetFrom($email_from, $name_from);
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
try{
    $mail->Send();
    echo "Success!";
} catch(Exception $e){
    echo "Fail - " . $mail->ErrorInfo;
}

错误输出:SMTP ERROR: Password command failed: 534-5.7.14SMTP错误:Could not authenticate.

对于那些使用PHPMailer进行身份验证失败的问题,并且所有设置和凭据都很好,请尝试使用以下命令:

$mail->AuthType = 'LOGIN';

:

我挣扎了很长时间,直到我添加了这个。

欢呼。