邮件程序错误:SMTP错误:以下SMTP错误:不接受数据

时间:2009-03-12 21:38:14

标签: php

以下代码给出了消息

Mailer Error: SMTP Error: The following SMTP Error: Data not accepted. But when I replace $EmailAdd with a a@yahoo.com. The mail was sent.

我的代码出了什么问题?我是php的新手,特别是在处理邮件功能方面。

$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   = "jsbadiola@gmail.com";  // GMAIL username
$mail->Password   = "********";            // GMAIL password
$mail->AddReplyTo("jsbadiola@gmail.com","Lord Skyhawk");
$mail->From       = "jsbadiola@gmail.com";
$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 个答案:

答案 0 :(得分:7)

我大多数时候都看过这条消息,电子邮件无论如何都成功发送,但并非总是如此。要进行调试,请设置:

$mail->SMTPDebug = true;

您可以回显调试消息或使用error_log()

记录它们
// 'echo' or 'error_log'
$mail->Debugoutput = 'echo';

特别是在负载很重的服务器上的可能候选者是SMTP超时:

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

class.smtp.php还有一个Timelimit属性,用于从服务器读取。

答案 1 :(得分:4)

如果你没有超过谷歌垃圾邮件实施的每日发送限制,这也会有所帮助。

答案 2 :(得分:3)

检查你查询db输出&amp;脚本中该点的变量值。确保它返回$ EmailADD的期望值。

执行var_dump($ EmailADD,true);

或尝试回显该查询的输出。如果您实际上从该查询中收到了电子邮件值,我不明白为什么它不起作用,特别是当您提到直接分配值时;没有sql查询。

答案 3 :(得分:0)

尝试其他SMTP服务器?看看是否有效?

或者只是不使用smtp服务器,大多数使用PHP的服务器也都有sendmail / postfix,所以可以自己转发电子邮件。

删除此位......

$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   = "jsbadiola@gmail.com";  // GMAIL username

$mail->Password   = "alucar";            // GMAIL password