PHPMailer SMTP ERROR:命令失败

时间:2014-12-22 18:44:05

标签: php smtp phpmailer

当我使用gmail有主机时,我的代码有效,但对于这个项目,我必须使用office365.com,我收到错误,我不知道该怎么做:

$mail = new PHPMailer;
    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->SMTPAuth   = true;           // enable SMTP authentication
    $mail->IsHTML(true);

    $mail->Host     = "smtp.office365.com";         // SMTP server
    $mail->SMTPSecure = "tls";                      // sets the prefix to the servier
    $mail->Port       = 587;                        // set the SMTP port for the GMAIL 
    $mail->Username   = "username";     // username
    $mail->Password   = "password";             // password

    //works with this (gmail)
    //$mail->Host     = "smtp.gmail.com"; // SMTP server
    //$mail->SMTPSecure = "tls";          // sets the prefix to the servier
    //$mail->Port       = 587;            // set the SMTP port for the GMAIL 
    //$mail->Username   = "username";  // GMAIL username
    //$mail->Password   = "password";            // GMAIL password

    $mail->setFrom('someEmailAdress');
    $mail->addReplyTo("someEmailAdress");

    $mail->AddAddress('someEmailAdress');

    $mail->Subject  = $_POST['ActivityType']." ".$_POST['DealerName'];
    $mail->Body     = $message;
    $mail->WordWrap = 400;
    $mail->IsHTML(true);
    $mail->SMTPDebug = 2;    
    $mail->Send();

这是我得到的错误

12014-12-22 18:15:39    SERVER -> CLIENT: 220 BY2PR05CA022.outlook.office365.com
    Microsoft ESMTP MAIL Service ready at Mon, 22 Dec 2014 18:15:39 +0000
2014-12-22 18:15:39 CLIENT -> SERVER: EHLO 192.168.1.53
2014-12-22 18:15:39 SERVER -> CLIENT: 250-BY2PR05CA022.outlook.office365.com Hello [24.37.210.58]

250-SIZE 78643200

250-PIPELINING

250-DSN

250-ENHANCEDSTATUSCODES

250-STARTTLS

250-8BITMIME

250-BINARYMIME

250 CHUNKING
2014-12-22 18:15:39 CLIENT -> SERVER: STARTTLS
2014-12-22 18:15:39 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2014-12-22 18:15:39 CLIENT -> SERVER: QUIT
2014-12-22 18:15:40 SERVER -> CLIENT:
2014-12-22 18:15:40 SMTP ERROR: QUIT command failed:
SMTP connect() failed

一直在努力弄清楚最近会发生什么,但是对于"将军"退出命令错误失败。特别是当gmail工作正常时,可以在office365那边吗?

2 个答案:

答案 0 :(得分:0)

btw outlook是最受限制的,特别是涉及到html电子邮件,这是你在你的选项中设置的,首先尝试发送到像gmail,也许是雅虎,但它又有一些限制,但gmail每次都有效没有任何probs,你也可以使用像 fakesmtp 这样的东西来捕获发送的电子邮件。

答案 1 :(得分:0)

抱歉还不能发表评论但请尝试这些

https://github.com/PHPMailer/PHPMailer/issues/189

或者可能是一个selinux的事情 http://osticket.com/forum/discussion/77982/resolved-smtp-office365-issue