gpt4 book ai didi

php - PHPMailer中的"SMTP Error: Could not authenticate"

转载 作者:IT王子 更新时间:2023-10-28 23:58:20 25 4
gpt4 key购买 nike

我在通过 Gmail 发送电子邮件的简单脚本中使用 PHPMailer,我收到“未知错误”(至少对我而言!):

SMTP Error: Could not authenticate. Error: SMTP Error: Could not authenticate.

SMTP server error: 5.7.1 Username and Password not accepted. Learn more at 535 5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257 p38sm2467302ybk.16

我读过有关为 SSL/TLS 连接配置 OpenSSL 的内容,并且我做到了。 Apache 和 PHP 已正确配置(在 PHP 中运行 OpenSSL 扩展,在 Apache 2.2.16 中运行 mod_ssl)。

这是 PHP 脚本:

 <?php
require_once ("PHPMailer\class.phpmailer.php");
$Correo = new PHPMailer();
$Correo->IsSMTP();
$Correo->SMTPAuth = true;
$Correo->SMTPSecure = "tls";
$Correo->Host = "smtp.gmail.com";
$Correo->Port = 587;
$Correo->UserName = "foo@gmail.com";
$Correo->Password = "gmailpassword";
$Correo->SetFrom('foo@gmail.com','De Yo');
$Correo->FromName = "From";
$Correo->AddAddress("bar@hotmail.com");
$Correo->Subject = "Prueba con PHPMailer";
$Correo->Body = "<H3>Bienvenido! Esto Funciona!</H3>";
$Correo->IsHTML (true);
if (!$Correo->Send())
{
echo "Error: $Correo->ErrorInfo";
}
else
{
echo "Message Sent!";
}
?>

用户名和密码都可以,我在 Thunderbird 中试过,没有任何问题。我还使用了 SSL 身份验证和端口 465,得到了同样的错误。

最佳答案

我遇到了这个问题。为了让它工作,我必须去 myaccount.google.com -> “登录和安全” -> “具有帐户访问权限的应用”,然后将“允许安全性较低的应用”设置为“开启”(靠近页面底部)。

您也可以关注 direct link to these settings

enter image description here

关于php - PHPMailer中的"SMTP Error: Could not authenticate",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3949824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com