【发布时间】:2012-12-14 17:33:30
【问题描述】:
我这里有个大问题! 我需要向我的所有订阅者(大约 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); 吗??
【问题讨论】:
-
如果您认为这是问题所在,为什么不使用
set_time_limit(0)? -
问题是我是 phpmailer 的新手,我遵循了一个教程,它说要设置一个时间限制......我认为这可能与它有关!你认为这可能是问题所在吗?将时间限制设置为 0 会让脚本永远运行,对吗?谢谢
-
我不是专家,但如果这是克制,那就是克制。这里有很多关于规避时间限制的问题,以及使用了哪些 php.ini 设置。我认为这与您的邮件功能无关,而与您的 php 设置有关。如果它花费的时间太长,你就会杀死不使用太多资源的功能(我假设)。如果你想让它继续下去,你必须做出改变(假设时间限制是问题)。
-
是的,我同意你的看法!我发布这个问题的主要原因是因为我想在浪费更多的钱发送浪费的电子邮件之前得到一些建议
-
我听到了!我可能会改写这个问题,以询问有关如何设置时间限制的建议,而不是“php邮件程序有什么问题”(这是我从问题中收集到的......虽然我可能是错的......)
标签: php email send phpmailer newsletter