Page 1 of 1

mail loop help!

Posted: Wed Sep 08, 2004 1:55 pm
by speedamp
hello everybody....

i am really close to what i want here, but can't get this script to output progress along the way.....it either times out or gives the results all at once (when it's done).....i want it to print line by line the output along the way so i can resend if it times out.

Code: Select all

while ($row = mysql_fetch_array($query)) 
{ 
$email = $row['email']; 
$fname = $row['fname']; 
$lname = $row['lname']; 
$bib = $row['bib']; 
$body = "$fname $lname,\n 
Your bib number is $bib\n"; 
stripslashes($body); 
strip_tags($body); 
stripslashes($subject); 
strip_tags($subject); 
mail($email, $subject, $body, $mailheaders); 
    echo "sending to ".$email."<Br>"; 
    flush(); 
    sleep(3); 
}
i have about 2000 entries in my db that i need to email blast....am i way off base in the way i'm doing this?

Thanks!
-Michael

Posted: Wed Sep 08, 2004 2:00 pm
by feyd
[php_man]set_time_limit[/php_man]

and flushing in the middle of the stream is only supported on certain servers. Additionally, it's always batched.

Posted: Thu Sep 09, 2004 12:34 pm
by speedamp
here is my latest idea: to write each email to a text file as they are sent....if i encounter a timeout, i should have all sent emails logged, so i can continue.

Code: Select all

ini_set('max_execution_time', '1000'); 
set_time_limit (1000); 

while ($row = mysql_fetch_array($query)) 
{ 
$email = $row['email']; 
$fname = $row['fname']; 
$lname = $row['lname']; 
$bib = $row['bib']; 
$from = "test@test.com"; 
$subject = "subject"; 
$mailheaders = "From: $from\n"; 
$mailheaders .= "Reply-To: $from\n\n"; 
$body = "$fname $lname,\n 
Your bib number is $bib\n"; 
stripslashes($body); 
strip_tags($body); 
stripslashes($subject); 
strip_tags($subject); 
stripslashes($mailheaders); 
strip_tags($mailheaders); 
mail($email, $subject, $body, $mailheaders); 
   $fp = fopen("log.txt","a"); 
   $content = "sent to ".$email."\r\n"; 
   fwrite($fp,$content); 
   fclose($fp); 
    sleep(3); 
} 
echo "done";

will this write to the file as it goes along, or will it wait (similar to my echo problems) and write it at competion?


-mike

Posted: Thu Sep 09, 2004 12:56 pm
by feyd
have you tried it?

Posted: Thu Sep 09, 2004 1:02 pm
by speedamp
yes, i have tried it on a small test area....but i do not want to test it on 1000 emails.....

does it seem like it's going to write them as they are sent, or will it write them upon completion of everything? ....meaning, if it times out, it won't write anything

Posted: Thu Sep 09, 2004 1:11 pm
by feyd
you open and close the file on each pass.. it's written as each one is done..

you are only allowing 1000 seconds to execute the script.. 1000 emails will take at least 3000, with the code you have.

Posted: Thu Sep 09, 2004 4:09 pm
by evilmonkey
I think you can change that in the php_int, or through .htaccess...

Speedamp, be sure not to get your domain blacklisted for spamming. ;)