php PHPMailer .Exception:SendAsDeniedException.MapiExceptionSendAsDenied
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40016305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHPMailer .Exception:SendAsDeniedException.MapiExceptionSendAsDenied
提问by Kevin Kloet
I have installed PHPMailer on my website. But, I can't get it to work the way it should. When I send an email through the website, I get the following error:
我已经在我的网站上安装了 PHPMailer。但是,我无法让它按应有的方式工作。当我通过网站发送电子邮件时,出现以下错误:
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
I put arrows where the actual error is. When I try to send an email using the same email as the receiving email, everything works the way I want it to. That's why I don't get it why it does this?
我将箭头放在实际错误所在的位置。当我尝试使用与接收电子邮件相同的电子邮件发送电子邮件时,一切都按我希望的方式工作。这就是为什么我不明白为什么它会这样做?
Here is the code that is used to send the email:
这是用于发送电子邮件的代码:
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.';
}
The php_openssl extension is enabled. I am using actual email addresses so it's not the case of using fake email addresses like [email protected].
php_openssl 扩展已启用。我使用的是实际的电子邮件地址,因此不会使用像 [email protected] 这样的虚假电子邮件地址。
My html:
我的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">×</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>
and the javascript for the totalMessage:
和 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();
}
}
);
What am I doing wrong here or what is the problem? Why I get the error message?
我在这里做错了什么或有什么问题?为什么我收到错误消息?
edit:
编辑:
debug level 2 error:
调试级别 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: <3e21fa1900a9d30d3d51187e7719add6@localhost>
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
edit 2:
编辑2:
the trim_input function if you need to know what it does:
如果您需要知道它的作用,请使用 trim_input 函数:
function trim_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
回答by Synchro
I'd guess that the culprit is this:
我猜罪魁祸首是这个:
$mail->FromName = trim_input($_POST['Name']);
What you're doing here is asking outlook to forge the from address by using arbitrary user input. This is generally a bad idea. The error message name suggests that this is where the problem is too: SendAsDeniedException
, i.e. it doesn't like who you're sending as.
您在这里所做的是要求 Outlook 通过使用任意用户输入来伪造发件人地址。这通常是一个坏主意。错误消息名称表明这也是问题所在:SendAsDeniedException
,即它不喜欢您发送的对象。
Try this instead:
试试这个:
$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']));
This is: put your own address as the from address (so you're not forging anything), and use the submitter's address as a reply to, and also use their name alongside the from address.
这是:把你自己的地址作为发件人地址(这样你就不会伪造任何东西),并使用提交者的地址作为回复,并在发件人地址旁边使用他们的名字。
This problem is covered in the PHPMailer troubleshooting guide.
这个问题在PHPMailer 故障排除指南中有介绍。
回答by Picard
This error can also mean another thing as it did for me. So make sure also if the $mail->From
address is the same as the address you're using to authorize because otherwise you'll see this error:
这个错误也可能意味着另一件事,就像它对我所做的那样。因此,还要确保该$mail->From
地址是否与您用于授权的地址相同,否则您将看到此错误:
554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;
Failed to process message due to a permanent exception with message Cannot submit message.
回答by Jeff Kremer
Office 365 requires the "<" and ">" characters since September 1st, 2018.
自 2018 年 9 月 1 日起,Office 365 需要“<”和“>”字符。
This can often be fixed by updating the settings on the device or printer by adding angle brackets ("<" and ">") around the Reply or Mail From address.
通常可以通过在“回复”或“邮件发件人”地址周围添加尖括号(“<”和“>”)来更新设备或打印机上的设置来解决此问题。
See Microsoft's supportfor details.
有关详细信息,请参阅Microsoft 的支持。
回答by Abd Abughazaleh
I solved by change
我通过改变解决了
$mail->setFrom('[email protected]', 'Your Name');
To be the same $mail->Username
要一样 $mail->Username
$mail->Username = '[email protected]';
to be like that :
是这样的:
$mail->setFrom('[email protected]', 'Your Name');