我正在使用drupal 6并尝试使用以下代码向所有用户发送电子邮件。问题是有时邮件发送给用户多次,但发送文件夹为每个用户保留1个条目。特别是雅虎ids有超过2个邮件(3到4)并且发送了2个发送到每个雅虎ID的电子邮件。有谁知道..
<?php
require("/var/www/drupal/sites/all/modules/smtp/phpmailer/class.phpmailer.php");
$con = mysql_connect("***","***","*****");
$select_db=mysql_select_db("drupaldb", $con);
$result = mysql_query("select uid,name,mail,data from users ");
while($row = mysql_fetch_array($result))
{
mailit($row['name'],$row['mail']);
flush();
sleep(3);
}
print "<br>*******************************************<br>";
function mailit($name,$rec)
{
$content="<div> Test mail </div>";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "**********";
$mail->Password = "*********";
$mail->From = "*********";
$mail->FromName = "****";
$mail->AddAddress($rec,$name);
$mail->Subject = "Test mail";
$mail->IsHTML(true);
$mail->Body = $content;
$mail->AltBody ='Test Mail';
if(!$mail->Send())
{
error_log("Mass Mail: ".$mail->ErrorInfo, 0);
echo "Mailer Error: " . $mail->ErrorInfo."<br>";
}
else
{
echo "Message has been sent to <b>".$name."</b> through <i>".$rec."</i><br>";
}
}
?>
答案 0 :(得分:1)
您的代码似乎很好。您确定不同的用户不共享某些电子邮件地址吗? mail
列应该归一化并UNIQUE
。此外,脚本是否被多次执行?