php - 邮件程序错误 : SMTP Error: The following SMTP Error: Data not accepted

标签 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");
}

最佳答案

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

$mail->SMTPDebug = true;

您可以回显调试消息或使用 error_log() 记录它们:

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

一个可能的候选者,尤其是在负载很重的服务器上,是 SMTP 超时:

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

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

关于php - 邮件程序错误 : SMTP Error: The following SMTP Error: Data not accepted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/640598/

相关文章:

php - FOSUserBundle 实体构造

php - 根据另一个下拉列表的输入显示下拉列表时出错

php - 多对多数据库架构

php - $_SESSION 不在页面之间传递值 php

php - Laravel 4 - 在验证类中访问身份验证类

php - API 调用失败 : Error executing API call (request): Unauthorized request

php - 无法显示来自 mysql 数据库的图像

php - 列出数据库表关系及其类型

php - 检查字符串是否只是空格?

php - 使用 for 循环将值添加到 MySQL 插入查询