51

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> abcdf@somedomain.com<br />
    <b>Message :</b> Here is the message info<br />
';

Here is the array of recipients' mails;

$recipients = array("abc@something.com","xyz@somtehing.com");

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

$mail = new PHPMailer(); 
$mail->IsSMTP();
$mail->From = "noreply@something.com"; 
$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

Yasin Yörük
  • 1,500
  • 7
  • 27
  • 51
  • 1
    Do you want to send via outer SMTP server? If not, there no need this line: `$mail->IsSMTP();` if yes configure the php mailer smtp properties. – Kovge Apr 08 '13 at 13:17
  • I use `SMTP server`. It was configured by server admin. And it's working properly. But sometimes emails not sending. – Yasin Yörük Apr 08 '13 at 13:18
  • The smtp server is on same server where your code is? – Kovge Apr 08 '13 at 13:20
  • I really wonder that error source is SMTP server or my code ? If the issue about my code, why it was sent sometimes ? – Yasin Yörük Apr 08 '13 at 13:20
  • @Kovge yes they all on same server. – Yasin Yörük Apr 08 '13 at 13:21
  • First is think try without the $mail->isSMTP(), if the php mail function is configured well on the server it is not needed. If this not work, the server admin must do 3 two steps: 1) Reconfigure the smtp server, 2) set the MX records well, 3) if it is needed configure the php mail function in php.ini I does not see problems in your code, problems could be on server config, or phpmailer config: http://phpmailer.worxware.com/index.php?pg=examplebsmtp, if you does not comment out the isSMTP row. – Kovge Apr 08 '13 at 13:24
  • I know it's really hard to carry out the idea. But I try to find a crumb to solve this problem. – Yasin Yörük Apr 08 '13 at 13:25
  • @Kovge Ok, I consider your comment. I hope, I'll solve this. – Yasin Yörük Apr 08 '13 at 13:28
  • do you have access to the SMTP server logs, to see why it isn't accepting the data? If it works sporadically there could be something in the data that the server doesn't like (as in email address, content, etc.. – Doon Apr 08 '13 at 15:44
  • I havent got access to SMTP logs. But today, I sent same email to all recipients one by one. It's been sent... It's ridiculous. – Yasin Yörük Apr 09 '13 at 10:46
  • Did you ever get a solution to this? I'm seeing a similar intermittent error - my mail server is Microsoft Exchange - is yours? – Hippyjim Sep 19 '13 at 13:34
  • I'm not. It's all about SMTP server. And I haven't got access to manage SMTP. System admin solved this problem. Our servers are Linux based. – Yasin Yörük Sep 19 '13 at 14:20

17 Answers17

67

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

pb2q
  • 58,613
  • 19
  • 146
  • 147
J Ha
  • 1,202
  • 13
  • 16
  • 24
    i don't understand why this has a lot of upvote and it has accepted as the correct answer. What does the answer even mean? "You should config: $mail->From like $mail->Username"? Sounds very vague. – PinoyStackOverflower May 25 '17 at 10:04
  • 2
    @PinoyStackOverflower did you see that comment "your server dosen't allow different sender and username" – J Ha May 25 '17 at 18:22
  • 4
    That is not what i'm pointing out. Did you see my comment? `You should config: $mail->From like $mail->Username"? Sounds very vague.` – PinoyStackOverflower May 31 '17 at 10:09
  • 3
    I think this is what was meant: Some servers require that the From email address is the same as the email address used to authenticate. Check your from name and match it to the username you use to login to your SMTP server. – Bob Ray Mar 19 '18 at 19:43
  • 1
    This means that the email at $mail->Username and $mail->From must be the same.. And that worked for me. thanks – StanLe3 Jun 03 '18 at 12:05
  • @JHa Which file should be updated with those settings? – Israel Jun 22 '21 at 02:30
  • Works fine for me. Thanks! – Fredmat Jul 28 '21 at 15:29
19

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;
zzapper
  • 4,743
  • 5
  • 48
  • 45
  • 2
    This is the best answer, because `Data not accepted` can be caused by several different things. Add the debug setting line just before the `$email->Send();` line, then retry, press CTRL-U, and read the very long log very carefully. – Nicolas Raoul Aug 09 '19 at 03:31
18

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:

  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.

And you're all set.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Jonathan LeRoux
  • 413
  • 3
  • 12
  • 3
    already verified (all domain , sender's email , recipient's email ) but still getting same issue – Saurabh Chandra Patel Dec 26 '14 at 07:03
  • 2
    I had forgotten to request that my AWS SES configuration be moved out of the AWS SES Sandbox mode. Any outbound email that is unverified will fail when in Sandbox mode. Once Amazon support approved moving my AWS SES configuration out of the Sandbox into production, things worked fine for me. Silly mistake, but maybe this comment will save someone else a few minutes. – icefield Jul 03 '19 at 01:16
9

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;
Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
phoenix
  • 1,629
  • 20
  • 11
  • This answer is also helpful for other types of errors (my e-mail addresses were valid, but for the wrong availability zone) – SanThee May 11 '18 at 04:00
  • 2
    This worked for me. The exception only showed "SMTP Error: Data not accepted", but enabling debug showed that SES was rejecting an unverified email. – Brad May 29 '18 at 16:56
  • 1
    Note for beginners: Add the `$mail->SMTPDebug = 4;` line *below* the `$mail = new PHPMailer(true);` line. – Nicolas Raoul Aug 05 '19 at 09:07
5

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.

Adam Szabo
  • 11,302
  • 18
  • 64
  • 100
3

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;
André A.
  • 53
  • 6
  • There is no such property as `MsgHTML`; there is a *method* called `msgHTML()` which sets both `Body` and `AltBody` - so the code you posted here will do nothing special. – Synchro May 14 '19 at 13:20
  • 1
    @Synchro he is using previous [version](https://github.com/PHPMailer/PHPMailer/releases/tag/v5.2.6). You can check the code on the link. – threeFatCat Jun 24 '19 at 02:51
  • What I said is still true in older versions; there has never been a property called `MsgHTML`. – Synchro Jun 24 '19 at 05:25
1

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

Matteo
  • 21
  • 3
1

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.

https://support.google.com/a/answer/166852?hl=en

brismuth
  • 36,149
  • 3
  • 34
  • 37
1

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.

Woody Hayday
  • 97
  • 1
  • 5
1

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.

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
Sadee
  • 3,010
  • 35
  • 36
0

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.

geekinit
  • 1,345
  • 2
  • 14
  • 17
0

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.

Dinesh Gurjar
  • 498
  • 5
  • 17
0

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.

beingalex
  • 2,416
  • 4
  • 32
  • 71
0

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.

NightOwl
  • 329
  • 2
  • 20
0

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.

0

Mailgun sanbox error

With $PHPMailer->SMTPDebug = true; I found out that when using the mailgun sandbox domain, the email has to be added to an authorized recipients list (which is on the right panel of the sandbox domain overview)

Samuel Gfeller
  • 840
  • 9
  • 19
0

It happen too, when you used stripslashes or addslashesh or real_escape_string.

Avoid these things inside email body, when your email execution code completed then you can add these lines in bottom.