4

The following code gives the message

Mailer Error: SMTP Error: The following SMTP Error: Data not accepted. But when I replace $EmailAdd with a [email protected]. The mail was sent.

What's wrong with my code? I'm kind of new in php, especially in dealing with mail functions.

$sql1 = "SELECT Email_Address FROM participantable where IDno=$studId";
$result1 = mysql_query($sql1);
while ($row1 = mysql_fetch_assoc($result1)){
    $EmailADD = $row1["Email_Address"];
}

//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');

include("class.phpmailer.php");
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();
$body             = $mail->getFile('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "[email protected]";  // GMAIL username
$mail->Password   = "********";            // GMAIL password
$mail->AddReplyTo("[email protected]","Lord Skyhawk");
$mail->From       = "[email protected]";
$mail->FromName   = "Update";
$mail->Subject    = "PHPMailer Test Subject via gmail";
$mail->Body       = "Hi,<br>This is the HTML BODY<br>";                      //HTML Body
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap   = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress($EmailADD, "Agta ka");
$mail->AddAttachment("images/phpmailer.gif");             // attachment
$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    $status = "Successfully Save!";
    header("location: User_retsched.php?IDno=$studId&status=$status&Lname=$Lname&Fname=$Fname&Course=$Course&Year=$Year");
}
4
  • 1
    You should go change your gmail password....
    – Paul Dixon
    Mar 12, 2009 at 21:51
  • but when i change $EmailAdd to a real email address like [email protected] then it sends the mail.
    – freshprogrammer
    Mar 12, 2009 at 21:55
  • i tried his gmail password - didn't work
    – benlumley
    Mar 12, 2009 at 22:08
  • i did not put the real password for the security of the account but it does really work, the problem was i cannot get the value of the email address from the the database. maybe that was the problem, but i dont know how to resolve it.
    – freshprogrammer
    Mar 12, 2009 at 22:11

4 Answers 4

7

Most times I've seen this message the email gets successfully sent anyway, but not always. To debug, set:

$mail->SMTPDebug = true;

You can either echo the debug messages or log them using error_log():

// 'echo' or 'error_log'
$mail->Debugoutput = 'echo';

A likely candidate especially on a heavily loaded server are the SMTP timeouts:

// default is 10
$mail->Timeout = 60;

class.smtp.php also has a Timelimit property used for reads from the server.

2
  • I was attaching a file that was too big for sending and the debugging tips helped me to determine that. Thanks!
    – Nick
    May 17, 2013 at 15:55
  • 1
    THANK YOU ANIMISM!!!!! For all those people having RANDOM "Data Not Accepted" errors on code you 'KNOW' works elsewhere (and your 'new server' acts up), try setting your $mail->Timeout to something greater than 10 (60 works perfectly..). I have been trying to find out what is causing this for weeks now, and with no luck until I found this post. Some servers apparently just cant handle the 10 second default, and need a little extra umph in this area. Don't believe? Try setting this to something even smaller than 10, like 5 or 2. Than try to set it to 60, note that this IS consistent!
    – NinjaKC
    Jun 10, 2016 at 23:34
4

It also helps if you have not exceeded your daily sending limit of Googles Spam inforcement.

2
  • 2
    A source link or the actual limit might be helpful.
    – JSuar
    Dec 13, 2012 at 0:02
  • This is the answer.. I think they limit you to 1000 or less emails a day (outgoing via SMTP)
    – reefine
    May 11, 2013 at 19:56
3

check you query to the db output & variable value at that point in the script. make sure it's returning the desired value for $EmailADD .

do a var_dump($EmailADD, true);

or try to echo somewhere the output of that query. If your actually receiving an email value from that query, I don't see why it shouldn't work, specially when you mention that assigning a value directly works; without sql query.

1
  • 1
    +1: I had the same error msg and invalid email in the AddAddress method was exactly my problem.
    – James
    Feb 1, 2010 at 23:28
0

Try a different SMTP server? See if that works?

Or just don't use an smtp server, most servers with PHP on also have sendmail/postfix, so can relay email themselves.

remove this bit ...

$mail->IsSMTP();

$mail->SMTPAuth   = true;                  // enable SMTP authentication

$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier

$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server

$mail->Port       = 465;                   // set the SMTP port for the GMAIL server

$mail->Username   = "[email protected]";  // GMAIL username

$mail->Password   = "alucar";            // GMAIL password
1
  • the SMTP work sir, but i think that the problem is on getting the email address fromt he database.
    – freshprogrammer
    Mar 12, 2009 at 22:13

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.