doucong3048 2016-06-21 06:47
浏览 278

PHPMailer SMTP错误:数据不被接受

I'm trying out PHPMailer using outlook.com's SMTP server but I keep getting SMTP Error I followed the example code from PHPMailer's github page, and I've also looked at other questions on SO, but the answers there don't solve my problem

This is the code

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

And here is the debug output

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.
  • 写回答

2条回答 默认 最新

  • dpfw3607 2016-06-21 07:11
    关注

    Maybe I'm wrong, but as far as I see you are using property "Body" for trying to send HTML data, but in the PHPmailer there is an MsgHTML property for that. Could be that this is the problem (as aforementioned maybe not, but it is worth of testing).

    Replace your line:

    $mail->Body = 'This is the HTML message body <b>in bold!</b>';

    by:

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

    And test ;)

    Good look,

    Ok, it seems that the above adds nothing. I have tested your code in a brand new yahoo.com mail account, and it is working pretty well. I have only change my personal account data and the require line:

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

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?