Forum Moderators: coopster

Message Too Old, No Replies

sleep ()

How can I use the sleep command with email

         

BenySay

1:38 am on Dec 13, 2003 (gmt 0)

10+ Year Member



Hello!

I have a small problem with my mailing-list... If I have only 5 or 6 name in the data base, it's work fine.
So, my mailing list is bigger than before and now I can't send any message.
I'm trying a couple of way to add sleep() command with no succes.

Can you help me, please?

Ben

Here is my code ( work but only if I have a couple of emails in the database ):

//Program that takes data from the page
//message.php and sends it
//Connect to database
mysql_connect("MySQLHOST","********xx","xxxxxx");

//Select the database we want to use
mysql_select_db("xxxxxxxxxx");

//Get the contents of the column Email from
//mailinglist table and put in an array.
$sql = "SELECT * FROM mailinglist";
$result = mysql_query($sql);

//data from the message.php page
$subject = $_POST["subject"];
$message = $_POST["message"];
$headers = "From: news@nightstudio.net\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1";
$sbj = stripslashes ($subject);
$msg = stripslashes ($message);

//Send message loop
While ($row = mysql_fetch_array($result)) {
$email = $row["email"];

//Take notice that we've included $subject and $message below
mail($email, $sbj, $msg, $headers);

jatar_k

1:57 am on Dec 13, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld BenySay,

While ($row = mysql_fetch_array($result)) {
$email = $row["email"];
mail($email, $sbj, $msg, $headers);
sleep(10);
}

this should halt the loop for 10 seconds after every email is sent.

Do you mean that none of the emails go out or do you get errors? You can test the return from the mail function. It returns true or false depending on the success.

[edited by: jatar_k at 2:14 am (utc) on Dec. 13, 2003]

BenySay

2:13 am on Dec 13, 2003 (gmt 0)

10+ Year Member



Wow! Quick Response! Great!

I don't have to close the line before the sleep? like this :

mail($email, $sbj, $msg, $headers);
sleep(10);

Thanks Jatar_k

BenySay

jatar_k

2:15 am on Dec 13, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sorry, bad paste job ;)

yes you have it right, I fixed mine too.

BenySay

5:11 pm on Dec 13, 2003 (gmt 0)

10+ Year Member



Hello Jatar_k,
Your suggestion looks to work there's a but, the script fail after maybe 12 or 15 sent. I've got around 300 names in my database mailing list. Any Ideas where is my problem?

jatar_k

9:11 pm on Dec 13, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



max execution time is probably killing the script I would bet. You may need to just send out smaller chunks at a time.

You could also turn sleep down to 2 or 1 and see what happens.

BenySay

1:19 am on Dec 14, 2003 (gmt 0)

10+ Year Member



Send out smaller chunks? How I can do that?

IanKelley

5:17 am on Dec 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You don't need to sleep after every email unless your mail server is already badly bogged down. Even then you'd only need to sleep for 1 second.

Sleep every 200 emails or so instead. It would also be a good idea to do a header refresh at each sleep to stop the script from timing out.

This is assuming, of course, that you don't feel up to writing the script to mail in the background like all self respecting mailer scripts ;-)