【发布时间】:2017-03-12 16:49:10
【问题描述】:
我正在使用 PHPMailer,当我尝试运行以下 PHP 时,我收到了以下错误消息:
无法发送邮件。邮件程序错误:SMTP 错误:数据未接受。SMTP 服务器错误:DATA END 命令失败详细信息:5.7.60 SMTP;客户端无权作为此发件人发送 SMTP 代码:550
php代码:
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'outlook.office365.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info@domain.com'; // SMTP username
$mail->Password = '*password*'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
【问题讨论】:
-
我猜
from@example.com不是您 Office365 帐户上的有效帐户 -
@RiggsFolly 我刚刚更改了它,但它仍然无法正常工作。任何其他想法。我需要更改其他文件中的内容吗?
-
你可以试试
smtp.office365.com作为你的HOST,outlook.office365.com是POP3的url -
@Binary111 你必须得到你的 gmail 帐户,然后设置,然后你必须确保不太安全的应用程序权限是可以的。
标签: php email office365 phpmailer