我有一个电子邮件脚本,每15分钟运行一次,应该使用PHP mailer发送一次电子邮件。出于某种原因,它一次发送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.";
?>
修改代码,使其每次运行时都能写入日志文件。我猜它只被打了3次电话。
示例:
file_put_contents("log.txt", $_SERVER['REQUEST_TIME'] . "n", FILE_APPEND);