phpmailer - The following SMTP Error: Data not accepted - php

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

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

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;

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.

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;

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.

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;

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

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

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.

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.

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.

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 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.

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.

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)

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.

Related

How to get failed response from SMTP mail server?

I am working on Laravel and I am trying to send an email with PHPMailer and my mail server is Zoho.
Here is my Code:
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.zoho.com';
$mail->SMTPAuth = true;
$mail->Username = 'ServerUserName';
$mail->Password = 'ServerUserPassword';
$mail->SMTPSecure = 'TLS';
$mail->Port = 587;
$mail->setFrom('itsupport#foo.net', 'Foo');
$mail->addAddress($email);
$mail->addReplyTo('noreply#foo.com', 'No-reply');
$mail->isHTML(true);
$mail->Subject = "Testing - " . $subject;
$mail->Body = $body;
if(!empty($attachment)) {
$mail->AddAttachment($attachment['abs_path'], $attachment['name']);
}
$mail->SMTPDebug = 2;
$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str"; echo "<br>";};
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
echo "Error"."<br>"."================================="."<br>"."<br>";
dd($mail);
} else {
$error = 'Message sent!'.$mail->ErrorInfo;
echo "Success"."<br>"."================================="."<br>"."<br>";
dd($mail);
}
My Scenarios
1) When I am sending an email with my Valid and Real email it gives me
success status and in my mail server its shows me in Sent tab.
2) But when I am sending an email with Valid but Fake email it gives me also Success status and when I check my mail server It gives
me this mail.
3) And in both scenarios in my debugging code it gives me always this return:
What I want
I want when a mail server return undelivered or failed mail it should return me an error code e.g. (550, 552, 553 etc) + Error Message. I search a lot but not find anything.
Is there any possibility that server return me the error code also.
Note: I tried my phpmailer code in try catch. But when I use fake email it dos not goes to catch.
You're misunderstanding the structure of email. Email uses an asynchronous store-and-forward approach, which means that can be sent successfully, but fail later, before it reaches its destination. This is completely unlike HTTP which gives immediate responses.
You are submitting the message successfully to Zoho's mail server, but then that server is failing to deliver the message to its intended destination, so it gets sent back as a bounce to the envelope sender address (the address in the SMTP MAIL FROM command, set via the Sender property in PHPMailer).
To handle bounces in your code, you can configure your mail server to pipe the inbound message into a script attached to your bounce address, for example as described in this article.
Unfortunately that's not the end of the story. While you will then have programmatic access to the bounced message, actually figuring out why it bounced and who bounced it is often difficult, if not impossible in some cases. For example, Microsoft Exchange sometimes sends bounces that do not contain any means of identifying the address the original message was sent to! You can address that particular shortcoming by using VERP addressing, where every message has a unique bounce address, which you can do with PHPMailer.
Writing bounce handlers is generally a very unpleasant experience that I recommend avoiding if you can. There is a commercial bounce classification library by BoogieTools that works well, but there is still a large element of guesswork and heuristics involved.

How to get the result of send email via SMTP protocol?

everybody,
I am working on Email system to send emails via SMTP protocol with PHP,
everything goes fine and now I can send messages without a problem, I have tow problems Actually and I hope I will find a solution,
1 - I send email to users using a phpmailer library, but I can not control and get the result of sending email because I send about 10 emails at one SMTP connection.
this is my send code
$mail = new PHPMailer;
$froms=$respu['froms'];
$mail->Timeout = 3600;
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $respu['server']; // Specify main and backup SMTP servers
$mail->SMTPAuth = $respu['authentication']; // Enable SMTP authentication
$mail->Username = $respu['username']; // SMTP username
$mail->Password = $respu['password']; // SMTP password
$mail->SMTPSecure = $respu['security']; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $respu['port']; // TCP port to connect to
$mail->SetFrom($respu['username'],$froms);
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->MsgHTML($message);
if(!$mail->Send()) {
//$errors=$mail->getSMTPInstance()->getError();
$date=date('Y-m-d h:i');
echo $msg= "Message Not Sent: to $to " . $mail->ErrorInfo;
$date=date('Y-m-d h:i');
$sql="insert into log (log_text,user_email,log_time,status)values ('$msg','$to','$date',0) ";
$this->query_return($sql);
exit();
} else {$date=date('Y-m-d h:i');
$sql="insert into log (log_text,user_email,log_time,status)values ( 'Message Sent Successfully ','$to','$date',1) ";
$this->query_return($sql);
}
the if(!$mail->Send()) condition return true every time even if the email is wrong . it working like to test if the SMTP connection is done or not, I want to know if the email received by users or not.
my second problem is, I have more than 3000 mail address and I want to send email to them at the same time, what is happening is the procedure take a long time and I have to wait for a long time to finish it, how can I do it faster.
For sending to lists, use the mailing list example provided with PHPMailer as a starting point. Also read the wiki article about sending to lists.
For maximum performance, you want to be submitting to a local or nearby mail server, which then takes responsibility for onward delivery. Some messages may fail to be delivered, in which case you will need to rely on bounce handlers; when a message fails to send, it will be returned to the Return-path address, which you can control by setting the Sender property in PHPMailer (by default it uses your From address). Note that as a sender you should never set a return-path header yourself; that's the receiving server's job.
Be warned though: handling bounces is very unpleasant; because bounce messages are fairly "invisible" in normal use, it means that they are extremely variable in quality. For example, it's possible for bounces from some Microsoft Exchange servers to omit the address that the message bounced for! You can handle that scenario (and many other shortcomings of badly-configured mail servers) by using VERP addressing to help you identify original recipient addresses, or even individual messages. However you deal with this, you need to be on very good speaking terms with your mail server. Using an external service to handle sends like this isn't necessarily any better, since they face exactly the same problems, though at least they may deal with much of the unpleasantness of bounce handling.
FYI I run https://smartmessages.net, an email marketing service; it's built around PHPMailer (which is partly why I'm the maintainer), and we can send at about 300 messages/second (using a very good mail server), so decent throughput is entirely possible with PHPMailer.

Language String Failed to load : Recipients_failed

I have a script that sends a mail to validate a form made by a user. It's a professional application so the mail isn't a spam and the users are members of the company.
Now my PHPmailer() function bug once in two randomly. I would like technical help to see if I did something wrong in my PHP code. So first of all, this is what it should do:
1) the user end his form
2) he has to choose who will receive the email (between 3 choices, and he can cross the 3 checkboxes)
3) One mail will be sent to each person he checked, with a simple link to see the result of the form.
But most of the time, I have this error message:
Language String failed to load:
Recipients_failed [mail]
*[Mail] = the email address*
The PHP script stops there, the page doesn't finish loading and the mail isn't send.
for the exemple, we'll say that in the first page we have [mail1], [mail2] and [mail3] who are 3 checkboxes.
Here is my code:
if(isset['[mail1]']){
$mail = new PHPmailer();
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->Host=*;
$mail->Port=*;
$mail->From='no-reply#*.fr';
$mail->FromName=*;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth=true;
$mail->Username='no-reply#*.fr';
$mail->Password='*';
$mail->AddAddress([mail1]);
$mail->Subject="*";
$mail->Body = utf8_decode("*");
if(!$mail->Send()){
die($mail->ErrorInfo);
}
$mail->SmtpClose();
unset($mail);
}
I think that the code is ok because this works sometimes, but doesn't work sometimes... What should I do? Speak to OVH or there is something I did wrong?
I think your question has nothing to do with PHP.
The error message simply tells you that one of the recipients does not exist - this message does not come from php but from the SMTP server you are using.
However: I don't know why the server shows you an error message "no translation" - you should contact "OVH" and ask.

How to know mail is send and read by user when sending mail using SMTP,PHPmailer

is anybody know any solution for below problem
in my project, i am send email to client using smtp and php mailer and gmail script. so when i am send mail gmail send mail to particular client. for that i am passing gmail login and user name which is valid. all mail are sending properly. but sometime it may happen that some client not receive mail and at that time i am not able to get or trace any error. so i there any way, when i am sending mail to client , and when client get it and read it at that time i got any kind of confirmation.
Please if anybody have any idea , help me out.
<?php
/**
* Simple example script using PHPMailer with exceptions enabled
* #package phpmailer
* #version $Id$
*/
require ('../class.phpmailer.php');
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$body = "Please return read receipt to me.";
$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "SMTP SERVER IP/DOMAIN"; // SMTP server
$mail->Username = "EMAIL USER ACCOUNT"; // SMTP server username
$mail->Password = "EMAIL USER PASSWORD"; // SMTP server password
$mail->IsSendmail(); // tell the class to use Sendmail
$mail->AddReplyTo("someone#something.com","SOMEONE");
$mail->From = "someone#something.com";
$mail->FromName = "SOMEONE";
$to = "other#something.com";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message[Test Read Receipt]";
$mail->ConfirmReadingTo = "someone#something.com"; //this is the command to request for read receipt. The read receipt email will send to the email address.
$mail->AltBody = "Please return read receipt to me."; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
?>
Some modification need to be done in above script.
Configure SMTP mail server.
Set the correct FROM & FROM Name (someone#something.com, SOMEONE)
Set the correct TO address
from
also
Delivery reports and read receipts in PHP mail
You can always add reply to mail address which will take care if there is any error so you will get email back, and for if it's read, include a picture (blank picture of 1 pixel will do) and add code in that picture like and you can see how many hits that image did recieve or recieved any at all.
You can check that things in two different ways like, by using the header "Disposition-Notification-To" to your mail function, it will not going to work in all case because most people choose not to send read receipts. If you could, from your server, influence whether or not this happened, a spammer could easily identify active and inactive email addresses quite easily.
You can set header like
$email_header .= "Disposition-Notification-To: $from";
$email_header .= "X-Confirm-Reading-To: $from";
now the another method to check is by placing an image and you can add a script to onload of that image, that script will send notification to your system that xxx user have read the mail so, in that way you can track delivery status of the mail.
In fact, I can't think of any way to confirm it's been delivered without also checking it gets read, either by including a image that is requested from your server and logged as having been accessed, or a link that the user must visit to see the full content of the message.
Neither are guaranteed (not all email clients will display images or use HTML) and not all 'delivered' messages will be read.
Though for more info https://en.wikipedia.org/wiki/Email_tracking

PHP bulk mail using "phpmailer" lands in SPAM

I am using the following PHP CODE to send BULK MAIL .But Mails seems to Land in SPAM.I am using "phpmailer" class to send the mail.
require 'mailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "info#gmail.com";
$mail->Password = "Bexwa44Puciz"; // GMAIL password
$mail->AddReplyTo('info#gmail.com', 'Info');
$Appname = 'info.com';
$_subject="Newsletter From: ".$Appname;
$ema=",";
$to_bcc=explode(",",$ema);
$mail->AddCustomHeader($headers);
foreach($to_bcc as $tb){
$mail->AddBCC($tb, $dname);
}
$_body ="News content";//$hid;
$mail->FromName = "info.com";
$mail->From="inf#gmail.com";
$mail->Subject = $_subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($_body);
if($mail->Send()){
echo "Done";
}else {
echo "Failed";
}
I experienced same. My website sends requests for data confirmation to users a few times each day while I do my daily data maintenance. I sent a test message to my Gmail address and found that if you read your mail through Gmail webmail interface it will sometimes tell you Why the message was spammed. Very useful. It gave the reason "A lot of messages from hp19.hostpapa.com were spam". I am on a budget shared server and I assume a hundred other spammers have bought accounts on the same machine as mine and are using it for evil. My site is non-profit so buying a dedicated box to avoid spam is not an option. So...
My solution was to change my CMS to not use PHP mail() at all. Now my CMS simply displays the message and a mailto: link with Subject parameter set. Now my process is to hit CTRL+C, Click the link, CTRL+V, and hit send. Messages are sent from my computer's IP Address (not on any blacklist) using my mail client, Thunderbird.
This takes me just a couple of seconds longer than it did when my CMS used PHP mail() to send the message for me. However I have found I am receiving a lot more replies so I am happy that the vast majority of messages are not getting spam-binned.
I appreciate this manual solution is not appropriate for automated bulk messaging but for small non-profit sites on shared server who trigger each message with a click, I thought it was worth sharing.
There are a number of reasons you could be going into someones spam box. Your email server could be blacklisted due to either you, or another user on your server. You can check it at http://mxtoolbox.com/blacklists.aspx
Also check your SPF records in your DNS

Categories