php - 错误:SMTP 错误:无法验证
问题描述
当我尝试使用 PHP SMTP 电子邮件服务器发送电子邮件时,出现以下错误。SMTP 错误:无法验证。无法发送消息。邮件程序错误:SMTP 错误:无法验证。
try {
//Server settings
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'xxxx@gmail.com'; //SMTP username
$mail->Password = 'xxxxxxx'; //SMTP password
$mail->SMTPSecure = 'tls'; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('tawiqha@gmail.com', 'reset');
$mail->addAddress($email); //Add a recipient
$mail->addReplyTo('no-replay@gmail.com', 'no-replay');
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'اعادة تعيين كلمة السر';
$mail->Body = $message;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
解决方案
推荐阅读
- c# - 如何干净利落地使用现有连接或创建/处置新连接?
- python - 将 .data 文件转换为 .c 的问题
- android - 如何在我的项目中使用 FirestorePagingAdapter 和选项?
- c++ - 为什么模板类型不能成为 C++ 中的友元类?
- python - 控制台日志/cmd.exe 未在 chromedriver 中关闭
- swift - 向 Core Data 添加数据时出现问题 - nil 不是合法参数
- hadoop - 有没有办法在为纱线构建的 giraph 中激活 Giraph Stats?
- java - 如何远程提交火花作业
- typescript - 使用 Const 变量编译 Typescript
- c# - 使用路由参数发布时无法将 FileStream 发送到 AWS(没有也可以正常工作)