php phpmailer - 以下 SMTP 错误:数据不被接受

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15880042/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:07:39  来源:igfitidea点击:

phpmailer - The following SMTP Error: Data not accepted

phpemailsmtpphpmailer

提问by Yasin Y?rük

I'm trying to figure out this issue for 6 hours. But there is nothing to make sense. Here is the scenario; There is a well formatted HTMLtemplate.

我试图找出这个问题 6 个小时。但没有任何意义。这是场景;有一个格式良好的HTML模板。

$mail_body = '
    <b>Message Num :</b> 769<br />
    <b>Message Date :</b> 2013-04-08 09:03:21<br />
    <b>Name :</b> John Doe<br />
    <b>Phone :</b> 123456789<br />
    <b>E-mail :</b> [email protected]<br />
    <b>Message :</b> Here is the message info<br />
';

Here is the array of recipients' mails;

这是收件人的邮件数组;

$recipients = array("[email protected]","[email protected]");

Everything looks fine and email ready to send.Here is the phpmailer config;

一切看起来都很好,电子邮件可以发送了。这是 phpmailer 配置;

$mail = new PHPMailer(); 
$mail->IsSMTP();
$mail->From = "[email protected]"; 
$mail->FromName = "TEST";
$mail->WordWrap = 50;

foreach($recipients as $mail_add) {
    $mail->AddAddress($mail_add);
}
$mail->IsHTML(true);
$mail->Subject = "TEST Subject";
$mail->Body = $mail_body;
if(!$mail->Send()) {
    echo $mail->ErrorInfo;
} else { 
        echo "Mail sent...";
}

Everything is same when I test it. But sometimes email was sent. Sometimes it was not sent. Give me the following error : The following SMTP Error: Data not accepted.

当我测试它时,一切都是一样的。但有时会发送电子邮件。有时它没有发送。给我以下错误:The following SMTP Error: Data not accepted.

I hope I explained

我希望我解释

回答by css.cutter

your server dosen't allow different sender and username you should config: $mail->Fromlike $mail->Username

您的服务器不允许您应该配置不同的发件人和用户名:$mail->From例如$mail->Username

回答by Jonathan LeRoux

For AWS users who work with Amazon SES in conjunction with PHPMailer, this error also appears when your "from" mail sender isn't a verified sender.

对于将 Amazon SES 与 PHPMailer 结合使用的 AWS 用户,当您的“发件人”邮件发件人不是经过验证的发件人时,也会出现此错误。

To add a verified sender:

要添加经过验证的发件人:

  1. Log in to your Amazon AWS console: https://console.aws.amazon.com

  2. Select "Amazon SES" from your list of available AWS applications

  3. Select, under "Verified Senders", the "Email Addresses" --> "Verify a new email address"

  4. Navigate to that new sender's email, click the confirmation e-mail's link.

  1. 登录您的 Amazon AWS 控制台:https: //console.aws.amazon.com

  2. 从可用 AWS 应用程序列表中选择“Amazon SES”

  3. 在“已验证的发件人”下选择“电子邮件地址”-->“验证新的电子邮件地址”

  4. 导航到该新发件人的电子邮件,单击确认电子邮件的链接。

And you're all set.

你已经准备好了。

回答by zzapper

set phpmailer to work in debug to see the "real" error behind the generic message 'SMTP Error: data not accepted' in our case the text in the message was triggering the smtp server spam filter.

将 phpmailer 设置为在调试中工作以查看通用消息“SMTP 错误:数据未接受”背后的“真实”错误,在我们的案例中,消息中的文本触发了 smtp 服务器垃圾邮件过滤器。

  $email->SMTPDebug = true;

回答by phoenix

Interestingly, I had the same exact issue and for me the problem was that my connection was timing out. To be able to see more details on my connections, I added $mail->SMTPDebug = 4;to my phpmailer (look up how to capture the debug since the default output function is echo).

有趣的是,我有同样的问题,对我来说问题是我的连接超时。为了能够查看有关我的连接的更多详细信息,我添加$mail->SMTPDebug = 4;到我的 phpmailer(查找如何捕获调试,因为默认输出函数是 echo)。

Here's the result:

结果如下:

SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is ""
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): timed-out (10 seconds)
SMTP -> FROM SERVER:
SMTP -> ERROR: DATA not accepted from server: 

The default timeout is set to 10 seconds. If your app can support more, add this line to your phpmailer:

默认超时设置为 10 秒。如果您的应用程序可以支持更多,请将此行添加到您的 phpmailer:

$mail->Timeout = 20;

回答by Adam Szabo

Over a certain message of size, it messes up the content when setting through $mail->Body.

超过一定大小的消息,通过 $mail->Body 设置时会弄乱内容。

You can test it, if it works well with small messages, but doesn't work with larger (over 4-6 kB), then this is the problem.

您可以测试它,如果它适用于小消息,但不适用于较大的消息(超过 4-6 kB),那么这就是问题所在。

It seems to be the problem of $mail->Body, so you can get around this by setting the HTML body manually via $mail->MsgHTML($message). And then you can try to only add the non-html body by $mail->AltBody.

这似乎是 $mail->Body 的问题,因此您可以通过 $mail->MsgHTML($message) 手动设置 HTML 正文来解决此问题。然后你可以尝试只通过 $mail->AltBody 添加非 html 正文。

Hope that I could help, feel free to provide more details, information.

希望我能帮上忙,随时提供更多详细信息,信息。

回答by André A.

I was using just

我只是使用

$mail->Body    = $message;

and for some sumbited forms the PHP was returning the error:

对于某些 sumbited 形式,PHP 返回错误:

SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: This message was classified as SPAM and may not be delivered SMTP code: 550

SMTP 错误:数据不被接受。SMTP 服务器错误:DATA END 命令失败详细信息:此邮件被归类为垃圾邮件,可能无法传送 SMTP 代码:550

I got it fixed adding this code after $mail->Body=$message :

我修复了在 $mail->Body=$message 之后添加此代码的问题:

$mail->MsgHTML = $message;
$mail->AltBody = $message;

回答by Matteo

Try to set the port on 26, this has fixed my problem with the message "data not accepted".

尝试将端口设置为 26,这解决了我的“数据未接受”消息问题。

回答by Woody Hayday

I was hitting this error with phpMailer + Amazon SES. The phpMailer error is not very descriptive:

我在使用 phpMailer + Amazon SES 时遇到了这个错误。phpMailer 错误不是很具有描述性:

2: message: SERVER -> CLIENT: 554 Transaction failed: Expected ';', got "\"
1: message: 
2: message: SMTP Error: data not accepted.

For me the issue was simply that I had the following as content type:

对我来说,问题只是我有以下内容类型:

$phpmailer->ContentType = 'text/html; charset=utf-8\r\n';

But that it shouldn't have the linebreak in it:

但它不应该有换行符:

$phpmailer->ContentType = 'text/html; charset=utf-8';

... I suspect this was legacy code from our older version. So basically, triple check every $phpmailer setting you're adding - the smallest detail counts.

...我怀疑这是我们旧版本的遗留代码。所以基本上,三重检查你添加的每个 $phpmailer 设置 - 最小的细节很重要。

回答by Sadee

First you better set debug to TRUE:

首先,您最好将调试设置为 TRUE:

$email->SMTPDebug = true;

$email->SMTPDebug = true;

Or temporary change value of public $SMTPDebug = false; in PHPMailer class.

或者临时更改public $SMTPDebug = false 的值;在 PHPMailer 类中。

And then you can see the full log in the browser. For me it was too many emails per second:

然后你可以在浏览器中看到完整的日志。对我来说,每秒发送的电子邮件太多了

...
SMTP -> FROM SERVER:XXX.XX.XX.X Ok
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "XXX.XX.XX.X Requested action not taken: too many emails per second "
SMTP -> get_lines(): $data is "XXX.XX.XX.X Requested action not taken: too many emails per second "
SMTP -> FROM SERVER:XXX.XX.XX.X Requested action not taken: too many emails per second
SMTP -> ERROR: DATA command not accepted from server: 550 5.7.0 Requested action not taken: too many emails per second
...

Thus I got to know what was the exact issue.

因此,我知道确切的问题是什么。

回答by Gabriel Cortes

in my case I was using AWS SES and I had to verify both "FromEmail" and "Recipient". Once done that I could send without problems.

就我而言,我使用的是 AWS SES,我必须同时验证“FromEmail”和“Recipient”。一旦完成,我可以毫无问题地发送。