Jump to content

Sending newsletter in cycles


dhimok

Recommended Posts

<?php

$emails = array("[email protected]", "[email protected]");

$message = "This email was sent by PHP!";

$from = "[email protected]";

$subject = "Sent from PHP";

foreach($emails as $email) {
$headers = "From: {$from}";
mail($email, $subject, $message, $headers);
echo "Sent to {$email}<br />\n";
}

?>

I have no problem sending the email. I was thinking more like lets say

I must send 1000 emails

 

so First I send 100 and then 100 and so on. Does the functions sleep() helps with this?

 

sending 100 and then

 

sleep(5) // 5 seconds

 

and then start again with the next set of emails until they are done

Everytime you refresh the page it will re-parse so unless you have something like a DB table to confirm which ones sent and which ones didn't you won't be able to.

 

You *may* be able to store them all as one huge array in a session variable but that would be pretty inefficent.

 

Maybe if you explained why exactly you want to take a break between e-mailing?

Use ini_set() to set the maximum execution time, and just loop through all of them. It won't timeout as long as it doesn't hit a neverending loop.

 

Exactly, like I said above. My server has a maximum execution time of 30 seconds, however I have a script that runs for a little of an hour. Execution time only exists when it hits a neverending loop and thus hangs executing that one function for the preset length of time.

 

To e-mail 1 million subscribers will take quite a while, but the PHP script won't timeout as long as it is pogrammed correctly without any never-ending loops.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.