tags:

views:

36

answers:

2

This program sends an email every 20 sec.

How can I amend the code to have it send an email, then pause for a random number of seconds between 1 and 20, then repeat till the end ? Any help on this is much appreciate. Thanks in advance!

Here is the code that is associated with the Delay section of the User Interface as it is

if (!$delaySecs) {

$delaySecs = 20; 

}

<input name="delaySecs" type="text" value="<? print $delaySecs; ?>" size="10">
A: 

Use the sleep function to pause execution.

If you are looking to pause the same amount of time between the sending of each email:

// $recipients is an array of email addresses    

foreach ($recipients as $recipient) {
    sendEmail($recipient);
    sleep($delaySecs);
}

I'm assuming you already know how to get the recipients and how to send the email. The above code is an example only how to pause between the sending of emails.

Jon Cram
+1  A: 

As i understand you are executing the mail function in a loop for x number of times.Use sleep(rand(1, 20)); before the execution.

Babiker