SMTP错误:无法进行身份验证。邮件程序错误:SMTP错误:无法进行身份验证

时间:2013-09-12 05:58:29

标签: php

include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "******@gmail.com"; // your SMTP username or your gmail username
$mail->Password = "******"; // your SMTP password or your gmail password
$from = "***********@example.com"; // Reply to this email
$to="******@gmail.com"; // Recipients email ID
$name=" Name"; // Recipient's name
$mail->From = $from;
$mail->FromName = "Webmaster"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->AddReplyTo($from,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Sending Email From Php Using Gmail";
$mail->Body = "This Email Send through phpmailer, This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}

我收到此错误

SMTP错误:无法进行身份验证。邮件程序错误:SMTP错误:无法进行身份验证。

任何人都可以帮助我吗?

提前致谢!

2 个答案:

答案 0 :(得分:2)

因为您使用的是SSL。添加此行代码

$mail->SMTPSecure = 'ssl';

同时更改

$mail->Host = "ssl://smtp.gmail.com";

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

另外,请确保您已启用扩展程序 php_openssl.dll

答案 1 :(得分:0)

如果您确定您的用户名和密码是正确的 然后执行这些步骤

1 $ mail - > SMTPSecure =' ssl';

2 $ mail->主持人=" smtp.gmail.com&#34 ;;

3 https://support.google.com/mail/answer/78754

4 去谷歌acocunts然后连接应用程序并更改为不太安全的应用程序 按照数字 3

中的所有步骤操作