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 HTML
template.
$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;
$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.
I hope I explained
In my case the problem was with the content of mail. When I changed content to simpler content without HTML, it worked. But after updating the phpmailer everything solved.
I was hitting this error with phpMailer + Amazon SES. The phpMailer error is not very descriptive:
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.
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).
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:
$mail->Timeout = 20;
Try to set the port on 26, this has fixed my problem with the message "data not accepted".
I was using just
$mail->Body = $message;
and for some sumbited forms the PHP was returning the error:
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
I got it fixed adding this code after $mail->Body=$message :
$mail->MsgHTML = $message;
$mail->AltBody = $message;
If you are using the Office 365 SMTP gateway then "SMTP Error: data not accepted." is the response you will get if the mailbox is full (even if you are just sending from it).
Try deleting some messages out of the mailbox.
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.
In my case in cpanel i have 'Register mail ids' option where i add my email address and after 30 minutes it works fine with simple php mail function.
We send email via the Gmail SMTP servers, and we get this exact error from PHPMailer sometimes when we hit our Gmail send limits.
You can check if it's the same thing happening to you by going into Gmail and trying to manually send an email. In our case that displays the more helpful error message about sending limits.
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.
To add a verified sender:
Log in to your Amazon AWS console: https://console.aws.amazon.com
Select "Amazon SES" from your list of available AWS applications
Select, under "Verified Senders", the "Email Addresses" --> "Verify a new email address"
Navigate to that new sender's email, click the confirmation e-mail's link.
And you're all set.
First you better set debug to TRUE:
$email->SMTPDebug = true;
Or temporary change value of public $SMTPDebug = false; in PHPMailer class.
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.
I was experiencing this same problem. In my instance the send mail was timing out because my Exchange server was relaying email to a server on the internet. That server had exceeded it's bandwidth quota. Apparently php mailer has some built in timeout and it wasn't long enough to see the actual message.
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.
$email->SMTPDebug = true;
Over a certain message of size, it messes up the content when setting through $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.
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.
Hope that I could help, feel free to provide more details, information.
Source: Stackoverflow.com