我这里有个大问题!我需要向我的所有订阅者(大约 1200 人)发送时事通讯,问题是它只向其中 150-180 人发送时事通讯。我有一个在 php 中实现的脚本,它使用 PhpMailer() 类将时事通讯发送给所有订阅者。
我在 MailJet 中购买了一个计划,该计划允许我每月发送 3 万封电子邮件,因此我使用他们的 SMTP 主机发送时事通讯。
这是我的脚本:
$mail = new PHPMailer();
$body = $message;
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "in.mailjet.com";
$mail->Port = 80;
$mail->Username = "username";
$mail->Password = "password";
// thing regarding the body, subject, etc of the email //
$to_list = explode(',',$to);
$between_delay = 75; //max limit of mails send at a slot
$send_count = 1;
$send_delay = 1; //Delays the program execution for the given number of seconds.
ignore_user_abort(true); // Ignore user aborts and allow the script to run forever
set_time_limit(300); //to prevent the script from dying
foreach($to_list as $row){
if ( ($send_count % $between_delay) == 0 ){
sleep( $send_delay ); //Delays the program execution for the given number of seconds.
}
$address = $row;
if(!empty($address)) {
$mail->AddAddress($address, "User");
$mail->Send();
$mail->ClearAddresses(); //clear address
}
$send_count++;
}
if(!empty($mail->ErrorInfo)) {
// display an error
}
我真的不知道可能是什么问题,但由于某种原因,它在大约 180 号之后停止发送电子邮件。可能是关于set_time_limit(300); ??