tags:

views:

2015

answers:

3

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");
}
A: 

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
benlumley
the SMTP work sir, but i think that the problem is on getting the email address fromt he database.
+2  A: 

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.

Codex73
+1: I had the same error msg and invalid email in the AddAddress method was exactly my problem.
James
A: 

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

subcool77