1
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 错误:无法验证。

4

2 回答 2

2

由于您使用的是 SSL。添加这行代码

$mail->SMTPSecure = 'ssl';

也改变你的

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

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

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

于 2013-09-12T06:02:24.420 回答
0

如果您确定您的用户名和密码正确,请执行以下步骤

1 $mail -> SMTPSecure = 'ssl';

2 $mail->主机=“smtp.gmail.com”;

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

4转到 google acocunts 然后连接应用程序并按照第3号中的所有步骤更改为不太安全的应用程序

于 2016-09-09T11:53:03.313 回答