编辑:在回顾之后,我在循环中发现了错误,这与标题无关。我把密码留在这里是为了帮助其他人。
我编写了这段发送电子邮件的代码,按下一个按钮,它工作得很好,但是在某个时候它随机停止了,而我没有改变它,显示错误对我来说No recipient addresses found in header.是没有意义的。请注意,我已经将print $to;放在代码的末尾,这样我就可以看到将什么设置为变量。我什么也得不到。空的地方。var_dump($to);返回NULL
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/common/config.php" ;
$id = $_GET['id'];
$table = $_GET['table'];
$q = mysql_query("SELECT * FROM $table WHERE loadID = '$id'");
while($f = mysql_fetch_array($q)){
$to = "noreply@example.com";
$subject = 'Dispatch information on Load: '.$f['loadnumber'].' for Truck: '.$f['trucknum'];
$random_hash = md5(date('r', time()));
$headers .= "From: dispatch@example.com\r\nReply-To: dispatch@example.com";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
ob_start();
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
EMAIL CONTENT GOES HERE
<?php } ?>
--PHP-alt-<?php echo $random_hash; ?>--
<?php
$message = ob_get_clean();
$mail_sent = @mail( $to, $subject, $message, $headers );
print $to;
?>发布于 2015-01-21 23:26:55
我注意到了一些问题。首先,在迭代过程中循环和设置$to和$header变量,这是多余的,并且用不必要的重复内容填充$header变量。它也不会为每一次迭代发送一封电子邮件,而是将越来越多的电子邮件堆成一封电子邮件,可能没有正确的格式化。此外,邮件函数中的$to参数与"To:“标头不一样。它很可能是一个脚本或精明的管理员抓住了这一点,并要求一个" to :“标题出现在电子邮件中。试试这个:
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/common/config.php" ;
$id = $_GET['id'];
$table = $_GET['table'];
$q = mysql_query("SELECT * FROM $table WHERE loadID = '$id'");
$random_hash = md5(date('r', time()));
$to = "noreply@example.com";
$headers = "To: $to\r\n";
$headers .= "From: dispatch@eagleexpress05.com\r\nReply-To: dispatch@eagleexpress05.com";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
while($f = mysql_fetch_array($q)){
$subject = 'Dispatch information on Load: '.$f['loadnumber'].' for Truck: '.$f['trucknum'];
ob_start();
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
EMAIL CONTENT GOES HERE
<?php
--PHP-alt-<?php echo $random_hash; ?>--<?php
$message = ob_get_clean();
$mail_sent = @mail( $to, $subject, $message, $headers );
}
print $to;
?>https://stackoverflow.com/questions/28078533
复制相似问题