【发布时间】:2020-12-02 14:34:39
【问题描述】:
我在通过 Gmail 发送电子邮件的简单脚本中使用 PHPMailer,我收到此错误(我确定电子邮件和密码组合正确):
!-- 2020-12-02 14:13:16 客户端 -> 服务器:EHLO 本地主机
2020-12-02 14:13:16 客户端 -> 服务器:STARTTLS
2020-12-02 14:13:17 客户端 -> 服务器:EHLO 本地主机
SMTP 错误:无法验证。
2020-12-02 14:13:17 客户端 -> 服务器:退出
SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
启用安全性较低的应用
这是我实现phpMailer的方式
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require './mailer/autoload.php';
$msg = "";
$mail = new PHPMailer();
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_CLIENT;
$mail->isSMTP();
$mail->Host = 'smtp.google.com';
$mail->SMTPAuth = true;
$mail->Username = '********@gmail.com';
$mail->Password = '********';
$mail->SMTPSecure = "tls";
$mail->Port = 25;
$mail->CharSet= 'UTF-8';
$mail->setFrom('*******@gmail.com', 'Mailer');
$mail->addAddress($_POST["mail"]);
$mail->isHTML(true);
$mail->Subject = $_POST["subject"];
$mail->Body = '<h2>E-mail</h2>';
$mail->AltBody = $_POST["content"];
$mail->send();
} catch (Exception $e) {
$msg = "An Error has Ocurr";
}
我该如何解决这个问题?
【问题讨论】: