2014-01-11 73 views
1

我有一個foreach循環和5000用戶在我的網站 ,我想向他們發送電子郵件PHP的foreach然後每100次睡眠繼續

然後每隔10個成員的睡眠5秒繼續

$headers = array(); 
$headers[] = "MIME-Version: 1.0"; 
$headers[] = "Content-type: text/plain; charset=iso-8859-1"; 
$headers[] = "From: Sender Name <[email protected]>"; 
$headers[] = "Bcc: JJ Chong <[email protected]>"; 
$headers[] = "Reply-To: Recipient Name <[email protected]>"; 
$headers[] = "Subject: {$subject}"; 
$headers[] = "X-Mailer: PHP/".phpversion(); 

$users = array('mohamed','ahmed'); 
foreach($users as $user){ 
mail($user, $subject, $email, implode("\r\n", $headers)); 
} 

如何做

+1

「每100次睡眠就會繼續」和「每10個成員」。所以你想要什麼??? – sergio

回答

9

使用模運算來檢測的10

foreach ($users as $i => $user) { 
    mail($user, $subject, $email, implode("\r\n", $headers)); 
    if ($i > 0 && $i % 10 == 0) { 
     sleep(5); 
    } 
} 
3
01的倍數