Forum Moderators: coopster
I`ve got this little mailing list I`m setting up. Now if there are a lot of e-mails in the list, to send a message to all of them in one go would be a bit of a strain on the server. So I was wondering if I could add some kind of sleep() function so that an x amount of messages are sent, before there is a slight pause, say 3 seconds, before the next batch are sent.
What do you think? Any ideas?
I`m using a loop to send all the emails, such as:
while ($row = mysql_fetch_array($result))
{
$emailall = $row[0];
$message = stripslashes($message);
mail("$emailall", "$subject", "$message", "From: $email");}
Thank you!
:)
A search there brings up the following page: sleep() [php.net] ;)
$send_count = 10;
$send_delay = 1;while ($row = mysql_fetch_array($result))
{
if($send_count == 0)
{
$send_count = 10;
sleep($send_delay);
}
$send_count--;
$emailall = $row[0];
$message = stripslashes($message);
mail("$emailall", "$subject", "$message", "From: $email");}
That'll send 10 messages, then pause 1 second, then send 10 messages... you get the picture.
[pre]
$between_delay = 10;
$send_delay = 1;
for ( $sent=0; $row = mysql_fetch_array($result); $sent++ ) {
if ( ($sent % $between_delay) == 0 )
sleep( $send_delay );
$emailall = $row[0];
$message = stripslashes($message);
mail("$emailall", "$subject", "$message", "From: $email");
}
[/pre]
ruserious, Are you sure about that BCC thing? I would suspect that since the server still has to make sure a copy of the email gets sent to every person, it would take roughly the same order of time as sending out all the messages individually.
The difference is in putting them in the queue. If you send each email seperately with mail(), you're calling sendmail each and everytime to queue one single message. With one email and xxx BCCs you only have that overhead once.