php 邮件程序错误:SMTP 错误:以下 SMTP 错误:数据不被接受
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/640598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mailer Error: SMTP Error: The following SMTP Error: Data not accepted
提问by Animism
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.
我的代码有什么问题?我对 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 = "[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");
}
回答by Animism
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():
您可以回显调试消息或使用error_log()以下命令记录它们:
// 'echo' or 'error_log'
$mail->Debugoutput = 'echo';
A likely candidate especially on a heavily loaded server are the SMTP timeouts:
一个可能的候选,尤其是在负载很重的服务器上是 SMTP 超时:
// default is 10
$mail->Timeout = 60;
class.smtp.phpalso has a Timelimitproperty used for reads from the server.
class.smtp.php还有一个Timelimit用于从服务器读取的属性。
回答by subcool77
It also helps if you have not exceeded your daily sending limit of Googles Spam inforcement.
如果您没有超过 Google 垃圾邮件强制执行的每日发送限制,它也会有所帮助。
回答by Codex73
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 .
检查您在脚本中的那个点查询数据库输出和变量值。确保它返回 $EmailADD 所需的值。
do a var_dump($EmailADD, true);
做一个 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.
或尝试在某处回显该查询的输出。如果您实际上从该查询中收到了电子邮件值,我不明白为什么它不应该起作用,特别是当您提到直接分配值时;没有sql查询。
回答by benlumley
Try a different SMTP server? See if that works?
尝试不同的 SMTP 服务器?看看行不行?
Or just don't use an smtp server, most servers with PHP on also have sendmail/postfix, so can relay email themselves.
或者只是不使用 smtp 服务器,大多数带有 PHP 的服务器也有 sendmail/postfix,因此可以自己中继电子邮件。
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

