2

I'm using a FOR loop to send emails from an array[250].

for ($counter = 0; $counter <= 250; $counter ++){
// send email function[$counter]

}

I thought about the sleep() function but since the server have limit excute time isn't an option. Please help me with this!

Asaf
  • 557
  • 1
  • 7
  • 15
  • You may be able to use [set_time_limit](http://us2.php.net/manual/en/function.set-time-limit.php) to allow your script to execute longer than the default. – Rusty Fausak Sep 22 '11 at 17:05

4 Answers4

1

To delay sending emails in a loop, you can create your own wait() function with a loop inside it and call it before iterating. If the reason you want to wait is to avoid problems with an ISP then read this SO Answer:

Sending mass email using PHP

Community
  • 1
  • 1
Todd Moses
  • 10,969
  • 10
  • 47
  • 65
0

Apparently (untested) the sleep function takes control away from php so the max execution time does not apply.

From: http://www.hackingwithphp.com/4/11/0/pausing-script-execution

"Note that the default maximum script execution time is 30 seconds, but you can use sleep() and usleep() to make your scripts go on for longer than that because technically PHP does not have control during the sleep operation."

PBSLuvr
  • 51
  • 4
0

Without some kind of scheduler you're always going to hit your execution limit. You may want to store the emails in a database then have cron execute them.

Or you can up your execution time:

<?php
   //replace 600 without how many seconds you need
   ini_set('max_execution_time', 600);

   ... loop through emails

?>

Why do you need to delay them anyways?

ActionOwl
  • 1,473
  • 2
  • 15
  • 20
  • 1
    To prevent gmail yahoo and any other mail provider to mark me as a spammer. I think I will set a cron any way , thank :) – Asaf Sep 22 '11 at 17:16
-1

Use cron - almost all hosts let you use it (except the free-host ones) and they should be more than happy to help you set it up if you need assistance (if they don't help you, don't give them your money)

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Cron job for what? I need to send email with a small delay (Like 5 seconds...) I don't think cron can help me here. Thanks for your comment! – Asaf Sep 22 '11 at 17:06
  • Ah, I see. I didn't understand where you intended to use sleep(). As rfausak says in a comment to your question, you can try using set_time_limit, but I know some hosts kill processes that run too long anyway. Still, most hosts will require you to tell them before you mass-send emails (to prevent spam), so either way you should be asking them for help. – Niet the Dark Absol Sep 22 '11 at 17:08