栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

无法通过PHPMailer使用Gmail SMTP服务器发送电子邮件,出现错误:在端口587上提交邮件需要SMTP AUTH。如何解决?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

无法通过PHPMailer使用Gmail SMTP服务器发送电子邮件,出现错误:在端口587上提交邮件需要SMTP AUTH。如何解决?

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = ‘ssl’; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com”;
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "email@gmail.com”;
$mail->Password = “password”;
$mail->SetFrom("example@gmail.com”);
$mail->Subject = “Test”;
$mail->Body = “hello”;
$mail->AddAddress("email@gmail.com”);


 if(!$mail->Send()) {    echo "Mailer Error: " . $mail->ErrorInfo; } else {    echo "Message has been sent"; }

上面的代码已经过测试并为我工作。

可能是您需要

$mail->SMTPSecure = 'ssl';

另外,请确保您没有为该帐户启用两步验证,因为这也会引起问题。

更新

您可以尝试将$ mail-> SMTP更改为:

$mail->SMTPSecure = 'tls';

值得注意的是,某些SMTP服务器会阻止连接。某些SMTP服务器不支持

SSL
(或
TLS
)连接。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/383261.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号