【发布时间】:2019-01-26 11:29:10
【问题描述】:
每当有人在我的网站上输入表单但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;
}
?>
出了什么问题?感谢您的帮助。
【问题讨论】: