php - SMTP:客户端:535 5.7.3 身份验证不成功
问题描述
每次有人在我的网站上输入表格但SMTP
不起作用时,我都会尝试发送电子邮件。它不断向我显示此错误。电子邮件帐户的凭据是正确的。另外,我已经尝试过SMTPAuth = False;
了,但结果还是一样。
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'TLS';
$mail->SMTPAuth = true;
$mail->Username = 'sender@test.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
//Recipients
$mail->setFrom('test@test.com', ' Services');
$mail->addAddress('recipient@test.com', $name); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Contact Us Message';
$mail->Body = 'Sent a message, This is the message :';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
header('Location: tempage.php');
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
出了什么问题?谢谢你的帮助。
解决方案
我也在为同样的问题苦苦挣扎 2 天。在我找到这个解决方案之后。它工作正常。尝试这个。
$mail->Host = 'smtp.office365.com'; 更改为 $mail->Host = 'smtp.live.com';
推荐阅读
- c# - 为什么 GDI+ 中的桌面描述符仅限于一台显示器?
- python - 从 c 到 Python 的 SWIG。将自定义方法添加到生成的 py 文件中
- python - Python - 尝试将 xml 转换为 csv 时出错
- java - 如何为 Map 传递 JSON 输入
键入 PUT JAX-RS API? - php - 1452 - 无法添加或更新子行
- gcloud - gcloud 命令更改当前目录的所有权
- linux - X秒后在while循环中递增计数器
- json - 在powershell中将嵌套的json转换为csv
- logstash - 如何为csv输入文件安排logstash
- python-3.x - 通过 Conda 安装 Keras 后 Spyder 崩溃