PHP 邮件发送到 Outlook:数据不被接受 RFC 2606 保留的收件人地址

And*_*uro 2 php email outlook phpmailer

当我尝试向我的 Outlook 帐户发送电子邮件时,我收到错误: SMTP 错误:数据未接受。邮件无法发送。邮件程序错误:SMTP 错误:数据未接受。SMTP 服务器错误:DATA END 命令失败详细信息:501 5.1.5 RFC 2606 保留的收件人地址 SMTP 代码:550 其他 SMTP 信息:5.3.4。我尝试使用 Gmail 帐户,它可以工作,但不能使用 Outlook Live。有人可以帮助我吗?

这是代码:

 <?php
require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->SMTPDebug = 2;                               // Enable verbose debug output

$mail->isSMTP();                     
$mail->Host = 'smtp-mail.outlook.com';              // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                             // Enable SMTP authentication
$mail->Username = 'andreacivitas@hotmail.it';       // SMTP username
$mail->Password = '***********';                    // SMTP password
$mail->SMTPSecure = 'TLS';                          // Enable TLS encryption, `ssl` also accepted
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);                            
$mail->Port = 587;                                             // TCP port to connect to

$mail->setFrom('andreacivitas@hotmail.it');
$mail->addAddress('andreacivitas@hotmail.it', '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';
}
?>
Run Code Online (Sandbox Code Playgroud)

Syn*_*hro 5

RFC2606定义了一些域,这些域被指定为仅供示例使用,并且保证永远不存在。特别是这些包括example.comexample.orgexample.net。这意味着您可以在示例代码中使用看起来合理的收件人,而不必担心无意中向随机人员发送电子邮件或其他流量,如果您使用虚构的名称(例如因为它实际上可能mydomain.com存在),则可能会发生这种情况。

您看到的错误已识别出您正在使用这样的保留域,因此拒绝接受您的提交。使用真实地址,或者删除使用保留地址的行,它就会起作用。

您设置的SMTPSecure选项不正确 - 它区分大小写,因此应该是:

$mail->SMTPSecure = 'tls';
Run Code Online (Sandbox Code Playgroud)

您通过SMTPOptionsOutlook/Hotmail 等通常提供可验证证书来禁用证书验证,因此您应该仅禁用验证来解决特定问题,因为这不是避免验证问题的安全方法,即除非您确实需要,否则不要这样做出于已知的特定原因。