通过脚本的电子邮件被列出3次?

时间:2011-06-02 21:04:58

标签: php phpmailer

我有一个每15分钟运行一次的电子邮件脚本,应该使用PHP邮件发送一次电子邮件。出于某种原因,它一次发送3封电子邮件。

这是我的代码:

<?php 

// Database connect

include("class.phpmailer.php");

$sql2 = "SELECT * FROM eblast_email WHERE id = '1'";
$result2 = mysql_query($sql2);
while ($myrow2 = mysql_fetch_array($result2)){

$get_event_id = "".$myrow2['event_id']."";

$mail = new PHPMailer();

// Login information here

$mail->Subject = "Subject here";

$html.= "HTML Message here";

$plain = "Plain Message here";

$mail->Body = $html;
$mail->AltBody = $plain;

$sql = "SELECT * FROM email_users WHERE sent = 'no' LIMIT 0, 40";
$result = mysql_query($sql);
while ($myrow = mysql_fetch_array($result)){

$email_to_send_to = "".$myrow['email']."";

$rsvp_check = mysql_query("SELECT * FROM event_members WHERE event_attending='$get_event_id' AND email='$email_to_send_to'");
$rsvp_check_done = mysql_num_rows($rsvp_check);

if ($rsvp_check_done == 0) {
$mail->AddAddress($email_to_send_to);
if(!$mail->Send()) {

echo "<b>Error sending email to " . $myrow['email'] . ". </b>" . $mail->ErrorInfo;
echo "<br>";
} else {
echo "Message to " . $myrow['email'] . " has been sent.<br>";
}
mysql_query("UPDATE email_users SET sent='yes' WHERE email='".$myrow['email']."'") or die (mysql_error());
$mail->ClearAddresses();

} else {
mysql_query("UPDATE email_users SET sent='yes' WHERE email='$email_to_send_to'") or die (mysql_error());
echo "$email_to_send_to has already registered ($rsvp_check_done) -- $get_event_id && $email_to_send_to<br>";
}

sleep(2);

}


}
echo "<br>Done.";

?>

1 个答案:

答案 0 :(得分:0)

修改代码以在每次运行时写入日志文件。我的猜测是它被调用了3次。

示例:

file_put_contents("log.txt", $_SERVER['REQUEST_TIME'] . "\n", FILE_APPEND);