【发布时间】:2022-06-29 19:57:08
【问题描述】:
此代码自一年以来一直有效,但今天突然停止工作。我没有更改gmail密码或任何东西。 gmail有更新吗? 我该如何解决这个问题?
错误: 无法发送消息。邮件程序错误:SMTP 错误:无法验证。
require_once '../db/config.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
function send_email($email, $code) {
require_once '../ml/PHPMailer/PHPMailer.php';
require_once '../ml/PHPMailer/SMTP.php';
require_once '../ml/PHPMailer/Exception.php';
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'example@gmail.com';
$mail->Password = 'aaaabbbbb';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
//Recipients
$mail->setFrom('example@gmail.com', 'mycompany');
$mail->addAddress($email);
$mail->addReplyTo('example@gmail.com', 'mycompany');
// Content
$mail->isHTML(true);
$mail->Subject = 'Verification code';
$mail->Body = 'Use the verification code to activate your account.
'.$code.'
';
$mail->AltBody = 'Use the verification code '.$code.' to activate your account';
$mail->send();
echo 'Verification code has been sent to your email '.$email;
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
-
它可能在一周前停止工作。阅读: support.google.com/accounts/answer/6010255?hl=en
-
是否有替代品。 Outlook smtp 会代替它工作吗?
-
您是否完整阅读了这篇文章?它已经提出了 3 种替代方案。
-
是的,如果您愿意,您可以切换到另一个 SMTP 提供商。
-
感谢@ADyson 的链接。我已经更新了 the PHPMailer troubleshooting guide ,提供了有关如何使用 gmail 身份验证的信息。