Jump to content

Sending newsletter in cycles


dhimok

Recommended Posts

Well it won't timeout :\ PHP Scripts will only timeout if they are stuck on a function for your max execution time. I have one massive database transfer script that takes about an hour to execute :P, thank god its my server or I'd have some ticked off NAs

Link to comment
Share on other sites

<?php

$emails = array("email1@site.com", "email2@site.com");

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

$from = "noreply@mysite.com";

$subject = "Sent from PHP";

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

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Well hypothetically speaking you could add an integer and an if statement saying

 

if( $i == 100 || $i == 200 ){
  
  sleep( 10 );

}

 

Then it would sleep on whatever numbers you specified, but I'm not sure why you would want to do that.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.