i have a foreach loop and 5000 user in my site and i want to send them emails
every 10 member sleep 5 second then continue
$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));
}
how to do it
Use the modulus operator to detect multiples of 10.
foreach ($users as $i => $user) {
mail($user, $subject, $email, implode("\r\n", $headers));
if ($i > 0 && $i % 10 == 0) {
sleep(5);
}
}
$count=0;
foreach($users as $user){
$count++;
mail($user, $subject, $email, implode("\r\n", $headers));
if(($count%10)==0)
{
sleep(5);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With