PHPMailer SMTP错误:未接受数据

PHPMailer SMTP错误:未接受数据,php,email,phpmailer,Php,Email,Phpmailer,我正在使用outlook.com的SMTP服务器试用PHPMailer,但一直收到SMTP错误 我遵循了PHPMailer的github页面中的示例代码,还研究了其他问题,但这些问题的答案并不能解决我的问题 这是密码 <?php date_default_timezone_set('Etc/UTC'); require_once 'vendor/autoload.php'; $mail = new PHPMailer; $mail->SMTPOptions = array(

我正在使用outlook.com的SMTP服务器试用PHPMailer,但一直收到SMTP错误 我遵循了PHPMailer的github页面中的示例代码,还研究了其他问题,但这些问题的答案并不能解决我的问题

这是密码

<?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!";
}

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

替换您的线路:

$mail->Body='这是以粗体显示的HTML邮件正文!'

作者:

$mail->MsgHTML('这是以粗体显示的HTML消息体!');
和测试;)

好样的

好的,看来上面的内容并没有增加什么。我已经在一个全新的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!";
}

阅读Synchro的评论后,我尝试先从web登录outlook,它给了我一个验证码来解决问题


后来我再次尝试运行该脚本,它起作用了,所以我猜是outlook的防机器人系统阻止了该脚本。

我有一个使用msgHTML的工作脚本(请看案例:tiny m)。还可以查看您的SMTP对邮件的协议限制(正确关闭、发送特定指示等)。看看
msgHTML
的功能:它是设置
Body
AltBody
以及图像内联和MIME类型设置的方便包装器。它可能会干扰你可能正在做的其他事情,因此直接设置
Body
是完全可以接受的。是的,我第一次尝试使用gmail,但出现了不同的错误、身份验证错误或其他问题,尽管我已经打开了允许不太安全的应用访问。所以我切换到了望台,我遇到了和开瓶器一样的问题,这解决了我的问题!谢谢你做的每件事都是对的——这看起来像是Outlook auth的古怪之处。表示如果您先通过其他方式登录,则会被清除。顺便说一句,你的密码很容易被破解,所以我会把它编辑出来,但你可能应该修改它。除非你真的必须禁用证书验证,因为特定的已知原因-例如,如果你的ISP防火墙透明地重定向你,验证可能会失败,在这种情况下,你将把你的密码给第三方。谢谢,我不知道我的密码在里面。我一直收到SSL证书错误,所以我禁用了验证,它仍然处于开发模式,所以现在还可以,我只想先让事情正常运行
$mail->MsgHTML('This is the HTML message body <b>in bold!</b>');
  <?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!";
}