繁体   English   中英

无法使用 Gmail 帐户在本地主机上通过 PHP 发送电子邮件

[英]Can't Send Email through PHP on localhost using Gmail account

2022 年 5 月 30 日Google更改了“不太安全的应用”设置,该设置不再可用。

不太安全的应用和您的 Google 帐户

为了帮助确保您的帐户安全,从 2022 年 5 月 30 日起,Google 不再支持使用第三方应用或设备,这些应用或设备要求您仅使用您的用户名和密码登录您的 Google 帐户。

因此,我无法使用 PHP 在 localhost 上发送电子邮件。

有没有其他方法可以做到这一点?

我将假设您通过 smtp 服务器连接到 Gmail。

如果您当前正在使用您要连接的 gmail 帐户的实际密码。 最好的办法是尝试创建应用程序密码并使用它。

使用应用密码登录

$mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
$mail->isSMTP();                                            //Send using SMTP
$mail->Host       = 'smtp.example.com';                     //Set the SMTP server to send through
$mail->SMTPAuth   = true;                                   //Enable SMTP authentication
$mail->Username   = 'user@example.com';                     //SMTP username
$mail->Password   = 'APPsPassword';                               //New apps password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
$mail->Port       = 465;                      

另一种选择是切换到Xoauth或使用 Oauth2 再次切换到 Gmail api。

$mail->oauthUserEmail = "[Redacted]@gmail.com";
$mail->oauthClientId = "[Redacted]";
$mail->oauthClientSecret = "[Redacted]";
$mail->oauthRefreshToken = "[Redacted]";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM