2016-10-13 36 views
1

我在我的網站上安裝了PHPMailer。 但是,我不能讓它按照它應該的方式工作。 當我通過網站,我收到以下錯誤發送電子郵件:PHPMailer .Exception:SendAsDeniedException.MapiExceptionSendAsDenied

08:12:53 CLIENT -> SERVER: RCPT TO: 2016-10-13 08:12:53 
CLIENT -> SERVER: DATA 2016-10-13 08:12:53 
CLIENT -> SERVER: Date: Thu, 13 Oct 2016 08:12:51 +0000 2016-10-13 08:12:53 
CLIENT -> SERVER: To: Kevin Kloet 2016-10-13 08:12:53 
CLIENT -> SERVER: From: Name <[email protected]> 2016-10-13 08:12:53 
CLIENT -> SERVER: Reply-To: Name <[email protected]> 2016-10-13 08:12:53  
CLIENT -> SERVER: Subject: Subject 2016-10-13 08:12:53 
CLIENT -> SERVER: Message-ID: 2016-10-13 08:12:53 
CLIENT -> SERVER: X-Mailer: PHPMailer5.2.15 (https://github.com/PHPMailer/PHPMailer) 2016-10-13 08:12:53  
CLIENT -> SERVER: MIME-Version: 1.0 2016-10-13 08:12:53 
CLIENT -> SERVER: Content-Type: text/plain; charset=UTF-8 2016-10-13 08:12:53 
CLIENT -> SERVER: 2016-10-13 08:12:53 
CLIENT -> SERVER: Name: Name 2016-10-13 08:12:53  
CLIENT -> SERVER: Email: [email protected] 2016-10-13 08:12:53 
CLIENT -> SERVER: Subject: Subject 2016-10-13 08:12:53 
CLIENT -> SERVER: Message: message 2016-10-13 08:12:53 
CLIENT -> SERVER: 2016-10-13 08:12:53 
CLIENT -> SERVER: . 2016-10-13 08:12:57 
SMTP ERROR: DATA END command failed: 550 5.3.4 554-554 5.2.0 
STOREDRV.Deliver; delivery result banner 2016-10-13 08:12:57  
--------> SMTP Error: data not accepted. Message was not sent.Mailer error: <-------- 
--------> SMTP Error: data not accepted.SMTP server error: <-------- 
DATA END command failed Detail: 554-554 5.2.0 
STOREDRV.Deliver; delivery result banner SMTP code: 550 Additional SMTP 
info: 5.3.4echo2016-10-13 08:12:57 
CLIENT -> SERVER: QUIT 2016-10-13 08:12:57 
SMTP ERROR: QUIT command failed: 554-554 5.2.0 
STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; 
Failed to process message due to a permanent exception with message Cannot 
submit message. 16.55847:6900000 

我把箭頭在實際誤差。

當我嘗試使用與接收電子郵件相同的電子郵件發送電子郵件時,所有的工作方式都是我想要的。這就是爲什麼我不明白它爲什麼這樣做。

這裏是用於發送電子郵件的代碼。

require("PHPMailerAutoload.php"); 

$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->Mailer = "smtp"; 
$mail->CharSet = 'UTF-8'; 
$mail->Host = 'tls://smtp-mail.outlook.com'; 
$mail->Port = "587"; // 8025, 587 and 25 can also be used. Use Port 465 for SSL. 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'tls'; 
$mail->Username = "username"; 
$mail->Password = "password"; 
$mail->From = trim_input($_POST['Email']); 
$mail->FromName = trim_input($_POST['Name']); 
$mail->AddAddress("[email protected]", "my name"); 
$mail->AddReplyTo(trim_input($_POST['Email']), trim_input($_POST['Name'])); 
$mail->SMTPDebug = 1; 
$mail->Subject = trim_input($_POST['Subject']); 
$mail->Body = trim_input($_POST['message']); 
$mail->WordWrap = 50; 

if (!$mail->Send()) { 
    echo 'Message was not sent.'; 
    echo 'Mailer error: ' . $mail->ErrorInfo; 
    exit; 
} else { 
    echo 'Message has been sent.'; 
} 

php_openssl擴展功能已啓用。 我正在使用實際的電子郵件地址,因此不是使用假電子郵件地址(如[email protected])的情況。

我的html:

<!-- modal --> 
<div id="myModal" class="modal fade" role="dialog"> 
    <div class="modal-dialog"> 

    <!-- Modal content--> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal">&times</button> 
     <h4 class="modal-title">Bericht sturen</h4> 
     </div> 
     <form method="POST" action="" > 
     <div class="modal-body"> 
      <label for="messageName">Uw naam: </label> 
      <input type="text" id="messageName" name="Name" /> 
      <label for="messageEmailAdress">Uw Emailadres: </label> 
      <input type="text" id="messageEmailAdress" name="Email" /> 
      <label for="messageSubject">Onderwerp van uw bericht: </label> 
      <input type="text" id="messageSubject" name="Subject" /> 
      <label for="message">bericht: </label> 
      <textarea id="message" rows="4" cols="50" name="Message"></textarea> 
      <input type="hidden" name="totalMessage" /> 
     </div> 
     <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Sluiten</button> 
     <input type="submit" name="Submit" class="btn btn-primary" value="Stuur bericht" /> 
     </div> 
     </form> 
    </div> 
    </div> 
</div> 

,爲totalMessage的JavaScript:

jQuery(document).ready(function() { 
var form = document.getElementsByTagName('form')[0]; 
if (form) { 
    form.addEventListener('submit', contact, false); 
} 
function contact(e) { 
    // Prevent Default Form Submission 
    e.preventDefault(); 

    var target = e.target || e.srcElement; 
    var i = 0; 
    var message = ''; 

    // Loop Through All Input Fields 
    for (i = 0; i < target.length; ++i) { 
     // Check to make sure it's a value. Don't need to include Buttons 
     if (target[i].type != 'text' && target[i].type != 'textarea') { 
      // Skip to next input since this one doesn't match our rules 
      continue; 
     } 

     // Add Input Name and value followed by a line break 
     message += target[i].name + ': ' + target[i].value + "\r\n"; 
    } 

    target.elements["totalMessage"].value = message; 
    this.submit(); 
    } 
    } 
); 

我在做什麼錯在這裏或者有什麼問題,爲什麼我得到錯誤信息?

編輯:

調試級別2錯誤:

2016-10-13 10:13:42 SERVER -> CLIENT: 220 BLU436-SMTP224.smtp.hotmail.com Microsoft ESMTP MAIL Service, Version: 8.0.9200.16384 ready at Thu, 13 Oct 2016 03:13:39 -0700 
2016-10-13 10:13:42 CLIENT -> SERVER: EHLO localhost 
2016-10-13 10:13:42 SERVER -> CLIENT: 250-BLU436-SMTP224.smtp.hotmail.com Hello [82.176.119.145] 250-TURN 250-SIZE 41943040 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY 250-TLS 250-STARTTLS 250 OK 
2016-10-13 10:13:42 CLIENT -> SERVER: STARTTLS 
2016-10-13 10:13:42 SERVER -> CLIENT: 220 2.0.0 SMTP server ready 
2016-10-13 10:13:42 CLIENT -> SERVER: EHLO localhost 
2016-10-13 10:13:42 SERVER -> CLIENT: 250-BLU436-SMTP224.smtp.hotmail.com Hello [82.176.119.145] 250-TURN 250-SIZE 41943040 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY 250-AUTH LOGIN PLAIN XOAUTH2 250 OK 
2016-10-13 10:13:42 CLIENT -> SERVER: AUTH LOGIN 
2016-10-13 10:13:42 SERVER -> CLIENT: 334 VXNlcm5hbWU6 
2016-10-13 10:13:42 CLIENT -> SERVER: xxx== 
2016-10-13 10:13:42 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 
2016-10-13 10:13:42 CLIENT -> SERVER: xxx 
2016-10-13 10:13:43 SERVER -> CLIENT: 235 2.7.0 Authentication succeeded 
2016-10-13 10:13:43 CLIENT -> SERVER: MAIL FROM: 
2016-10-13 10:13:43 SERVER -> CLIENT: 250 2.1.0 [email protected] OK 
2016-10-13 10:13:43 CLIENT -> SERVER: RCPT TO: 
2016-10-13 10:13:43 SERVER -> CLIENT: 250 2.1.5 [email protected] 
2016-10-13 10:13:43 CLIENT -> SERVER: DATA 
2016-10-13 10:13:43 SERVER -> CLIENT: 354 Start mail input; end with . 
2016-10-13 10:13:43 CLIENT -> SERVER: Date: Thu, 13 Oct 2016 10:13:41 +0000 
2016-10-13 10:13:43 CLIENT -> SERVER: To: Kevin Kloet 
2016-10-13 10:13:43 CLIENT -> SERVER: From: this is my name 
2016-10-13 10:13:43 CLIENT -> SERVER: Reply-To: this is my name 
2016-10-13 10:13:43 CLIENT -> SERVER: Subject: subject 
2016-10-13 10:13:43 CLIENT -> SERVER: Message-ID: <[email protected]> 
2016-10-13 10:13:43 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.16 (https://github.com/PHPMailer/PHPMailer) 
2016-10-13 10:13:43 CLIENT -> SERVER: MIME-Version: 1.0 
2016-10-13 10:13:43 CLIENT -> SERVER: Content-Type: text/plain; charset=UTF-8 
2016-10-13 10:13:43 CLIENT -> SERVER: 
2016-10-13 10:13:43 CLIENT -> SERVER: Name: this is my name 
2016-10-13 10:13:43 CLIENT -> SERVER: Email: [email protected] 
2016-10-13 10:13:43 CLIENT -> SERVER: Subject: subject 
2016-10-13 10:13:43 CLIENT -> SERVER: Message: this is the message 
2016-10-13 10:13:43 CLIENT -> SERVER: 
2016-10-13 10:13:43 CLIENT -> SERVER: . 
2016-10-13 10:13:49 SERVER -> CLIENT: 550 5.3.4 554-554 5.2.0 STOREDRV.Deliver; delivery result banner 
2016-10-13 10:13:49 SMTP ERROR: DATA END command failed: 550 5.3.4 554-554 5.2.0 STOREDRV.Deliver; delivery result banner 
2016-10-13 10:13:49 SMTP Error: data not accepted. Message was not sent.Mailer error: 
    SMTP Error: data not accepted. 
    SMTP server error: DATA END command failed Detail: 554-554 5.2.0 
    STOREDRV.Deliver; delivery result banner 
    SMTP code: 550 Additional 
    SMTP info: 5.3.4echo 
2016-10-13 10:13:49 CLIENT -> SERVER: QUIT 
2016-10-13 10:13:49 SERVER -> CLIENT: 554-554 5.2.0 
    STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:6900000 2016-10-13 10:13:49 
    SMTP ERROR: QUIT command failed: 554-554 5.2.0 
    STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:6900000 

編輯2:

的trim_input功能,如果你需要知道它做什麼:

function trim_input($data) { 
$data = trim($data); 
$data = stripslashes($data); 
$data = htmlspecialchars($data); 
return $data; 
} 
+0

設置'SMTPDebug = 2',以便您可以看到服務器在說什麼。 – Synchro

+0

也使用最新的PHPMailer(5.2.16)。 – Synchro

+0

我已更新至最新版本。 也設置SMTPDebug = 2,我猜這是與某事有關: 梅勒錯誤:SMTP錯誤:數據不被接受。 但它並沒有告訴我什麼數據不被接受。 –

回答

3

我d猜猜罪魁禍首是這樣的:

$mail->FromName = trim_input($_POST['Name']); 

您在這裏做的是要求Outlook使用任意的用戶輸入僞造發件人地址。這通常是一個壞主意。錯誤消息名稱表明這是問題的來源:SendAsDeniedException,即它不喜歡您發送的人。

試試這個:

$mail->From = trim_input("[email protected]"); 
$mail->FromName = trim_input($_POST['Name']); 
$mail->AddAddress("[email protected]", "my name"); 
$mail->AddReplyTo(trim_input($_POST['Email']), trim_input($_POST['Name'])); 

這就是:從地址(這樣你就不會鍛造什麼)把自己的地址作爲,並使用提交者的地址作爲回覆,並用自己的名字旁邊的地址。

此問題在the PHPMailer troubleshooting guide中涵蓋。

+1

似乎已經解決了我的問題。 謝謝。 –

+0

非常感謝! – technophyle