【问题标题】:PHPMailer SMTP Error: data not acceptedPHPMailer SMTP 错误:数据不被接受
【发布时间】:2016-10-22 13:58:55
【问题描述】:

我正在使用 Outlook.com 的 SMTP 服务器试用 PHPMailer,但我不断收到 SMTP 错误 我遵循了 PHPMailer 的 github 页面中的示例代码,并且我还查看了关于 SO 的其他问题,但那里的答案并没有解决我的问题

这是代码

<?php

date_default_timezone_set('Etc/UTC');

require_once 'vendor/autoload.php';
$mail = new PHPMailer;

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

//Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'smtp-mail.outlook.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication
$mail->Username = "user@outlook.com";

//Password to use for SMTP authentication
$mail->Password = "pass";

//Set who the message is to be sent from
$mail->setFrom('user@outlook.com', 'User');

//Set who the message is to be sent to
$mail->addAddress('recipient@gmail.com', 'Recipient');

//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';


$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';

//send the message, check for errors
if (!$mail->send()) {
    echo "<br><br>Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

这是调试输出

SERVER -> CLIENT: 220 BLU436-SMTP81.smtp.hotmail.com Microsoft ESMTP MAIL Service, Version: 8.0.9200.16384 ready at Mon, 20 Jun 2016 23:35:39 -0700 
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-BLU436-SMTP81.smtp.hotmail.com Hello [139.193.110.46]250-TURN250-SIZE 41943040250-ETRN250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-8bitmime250-VRFY250-TLS250-STARTTLS250 OK
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 SMTP server ready
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-BLU436-SMTP81.smtp.hotmail.com Hello [139.193.110.46]250-TURN250-SIZE 41943040250-ETRN250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-8bitmime250-VRFY250-AUTH LOGIN PLAIN XOAUTH2250 OK
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: xxx==
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: xxx=
SERVER -> CLIENT: 235 2.7.0 Authentication succeeded
CLIENT -> SERVER: MAIL FROM:<user@outlook.com>
SERVER -> CLIENT: 250 2.1.0 user@outlook.com....Sender OK
CLIENT -> SERVER: RCPT TO:<Recipient@gmail.com>
SERVER -> CLIENT: 250 2.1.5 Recipient@gmail.com 
CLIENT -> SERVER: DATA
SERVER -> CLIENT: 354 Start mail input; end with <CRLF>.<CRLF>
CLIENT -> SERVER: Date: Tue, 21 Jun 2016 06:35:39 +0000
CLIENT -> SERVER: To: Recipient <Recipient@gmail.com>
CLIENT -> SERVER: From: User <user@outlook.com>
CLIENT -> SERVER: Subject: PHPMailer SMTP test
CLIENT -> SERVER: Message-ID: <405c2ef139a1fa30da7bd01a6f945eb0@localhost>
CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.16 (https://github.com/PHPMailer/PHPMailer)
CLIENT -> SERVER: MIME-Version: 1.0
CLIENT -> SERVER: Content-Type: multipart/alternative;
CLIENT -> SERVER: boundary="b1_405c2ef139a1fa30da7bd01a6f945eb0"
CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
CLIENT -> SERVER: 
CLIENT -> SERVER: This is a multi-part message in MIME format.
CLIENT -> SERVER: 
CLIENT -> SERVER: --b1_405c2ef139a1fa30da7bd01a6f945eb0
CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
CLIENT -> SERVER: 
CLIENT -> SERVER: This is a plain-text message body
CLIENT -> SERVER: 
CLIENT -> SERVER: 
CLIENT -> SERVER: --b1_405c2ef139a1fa30da7bd01a6f945eb0
CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
CLIENT -> SERVER: 
CLIENT -> SERVER: This is the HTML message body <b>in bold!</b>
CLIENT -> SERVER: 
CLIENT -> SERVER: 
CLIENT -> SERVER: 
CLIENT -> SERVER: --b1_405c2ef139a1fa30da7bd01a6f945eb0--
CLIENT -> SERVER: 
CLIENT -> SERVER: .
SERVER -> CLIENT: 550 5.3.4 554-554 5.2.0 STOREDRV.Deliver; delivery result banner
SMTP ERROR: DATA END command failed: 550 5.3.4 554-554 5.2.0 STOREDRV.Deliver; delivery result banner
SMTP Error: data not accepted.

【问题讨论】:

  • 你做的一切都是正确的 - 这看起来像一个 Outlook auth 奇怪的东西。 This link建议先通过其他方式登录会清除。顺便说一句,您的密码很容易被解码,因此我将其编辑出来,但您可能应该更改它。
  • 不要禁用证书验证,除非您出于特定的已知原因确实必须这样做 - 例如,如果您的 ISP 的防火墙透明地重定向您,验证可能会失败,在这种情况下,您需要将密码提供给第三方。
  • 谢谢,我没有意识到我的密码在那里。我不断收到 SSL 证书错误,所以我禁用了验证,它仍处于开发模式,所以现在没关系,我只想让事情先正常运行

标签: php email phpmailer


【解决方案1】:

也许我错了,但据我所知,您正在使用属性“Body”来尝试发送 HTML 数据,但在 PHPmailer 中有一个 MsgHTML 属性。可能是这就是问题所在(如前所述,可能不是,但值得测试)。

更换你的线路:

$mail-&gt;Body = 'This is the HTML message body &lt;b&gt;in bold!&lt;/b&gt;';

作者:

$mail->MsgHTML('This is the HTML message body <b>in bold!</b>');

然后测试 ;)

好看,

好的,上面的内容似乎没有添加任何内容。我已经在一个全新的 yahoo.com 邮件帐户中测试了您的代码,并且运行良好。我只更改了我的个人帐户数据和要求行:

  <?php

date_default_timezone_set('Etc/UTC');

require_once 'include/PHPMaile/PHPMailerAutoload.php';
$mail = new PHPMailer;

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

//Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'smtp.mail.yahoo.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication
$mail->Username = "xxx@yahoo.com";

//Password to use for SMTP authentication
$mail->Password = "xxx";

//Set who the message is to be sent from
$mail->setFrom('xxx@yahoo.com', 'User');

//Set who the message is to be sent to
$mail->addAddress('xxx@xxx.com', 'Recipient');

//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';


$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';

//send the message, check for errors
if (!$mail->send()) {
    echo "<br><br>Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

希望这会有所帮助。

【讨论】:

  • 我有一个使用 msgHTML 的工作脚本(查看案例:tiny m)。还要查看您的 SMTP 对邮件的协议限制(正确关闭,发送特定说明,...)
  • 不。看看msgHTML 做了什么:它是使用图像内联和 MIME 类型设置设置 BodyAltBody 的便捷包装器。它可能会干扰您可能正在做的其他事情,因此直接设置Body 是完全可以接受的。
  • 是的,我第一次尝试使用 gmail,但出现了不同的错误、身份验证错误或其他问题,即使我已经打开了允许不太安全的应用程序访问。所以我切换到了前景
  • 我遇到了和开瓶器一样的问题,这解决了我的问题!谢谢!!
【解决方案2】:

在阅读了 Synchro 的评论后,我尝试先从 web 登录到 Outlook,它给了我一个验证码来解决。

之后我再次尝试运行该脚本,它可以工作,所以我猜是 Outlook 的 bot-prevention 系统阻止了该脚本。

【讨论】:

    猜你喜欢
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 2017-10-15
    • 1970-01-01
    • 2017-01-19
    相关资源
    最近更新 更多