2016-06-21 232 views
2

我嘗試使用outlook.com的SMTP服務器PHPMailer,但我不斷收到SMTP錯誤 我跟着來自PHPMailer的github頁面的示例代碼,我也看了其他關於SO ,但答案有沒有解決我的問題PHPMailer SMTP錯誤:數據不被接受

這是代碼

<?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 = "[email protected]"; 

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

//Set who the message is to be sent from 
$mail->setFrom('[email protected]', 'User'); 

//Set who the message is to be sent to 
$mail->addAddress('[email protected]', '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:<[email protected]> 
SERVER -> CLIENT: 250 2.1.0 [email protected] OK 
CLIENT -> SERVER: RCPT TO:<[email protected]> 
SERVER -> CLIENT: 250 2.1.5 [email protected] 
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 <[email protected]> 
CLIENT -> SERVER: From: User <[email protected]> 
CLIENT -> SERVER: Subject: PHPMailer SMTP test 
CLIENT -> SERVER: Message-ID: <[email protected]> 
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. 
+1

你正在做的一切正確 - 這看起來像一個Outlook auth怪胎。 [此鏈接](https://www.example-code.com/csharp/smtp_hotmail_live.asp)表明,如果您先以其他方式登錄,它將會清除。順便說一句,你的密碼很容易解碼,所以我會編輯它,但你應該改變它。 – Synchro

+1

不要禁用證書驗證,除非您確實必須爲特定的已知原因 - 例如,如果您的ISP的防火牆透明地重定向您,驗證可能會失敗,在這種情況下,您會將密碼提供給第三方。 – Synchro

+0

謝謝,我沒有意識到我的密碼在那裏。我不斷收到SSL證書錯誤,所以我禁用了驗證,它仍然處於開發模式,所以現在沒關係,我只想讓事情第一個工作 –

回答

-1

也許我錯了,但據我看到你正在使用屬性「Body」來嘗試發送HTML數據,但在PHPmailer中有一個MsgHTML屬性。可能是這是問題(如前所述可能不是,但它是值得的測試)。

替換您行:

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

由:

$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 = "[email protected]"; 

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

//Set who the message is to be sent from 
$mail->setFrom('[email protected]', 'User'); 

//Set who the message is to be sent to 
$mail->addAddress('[email protected]', '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!"; 
} 

希望這有助於。

+0

我剛剛嘗試過這個,同樣的錯誤 –

+0

你試過另一個SMTP服務器了嗎? –

+0

我有一個工作腳本,我使用msgHTML(看案例:小米)。也看看你的郵件的SMTP協議限制(正確關閉,發送特定指令,...) – Goufalite

0

在閱讀Synchro的評論之後,我嘗試先從Web登錄到Outlook,然後它給了我一個驗證碼來解決。

之後,我試着再次運行腳本,它的工作原理,所以我想這是Outlook的殭屍預防系統阻止腳本。

相關問題