mandingueiro wrote:tasairis wrote:Consider using a mailing service to do the work for you.
I want to make the script myself that's why I came here for help. I simply want to learn how to make this in batch php and send 10 mails each time.
You could certainly do that. If you have control of the configuration of the SMTP server that you're using, you should be able to set the timeout, but if not, you could code an inner loop that sends, say, 25 emails, then pauses for a few seconds and sends another 25. I have a monthly mailing of about 30, using my web host's SMTP server, and I've never had a time-out problem. If you're asking about the syntax of such a loop, I would try something along these lines:
Code: Select all
...
$done=0;
while($done=0) {
for($i=0;$i<25;$i++) {
while($row=mysql_fetch_array($result)) {
//
// assemble your email headers, Subject and Body data
//
mail($to,$subject,$message,$headers,$parameters);
}
if(!$row) {
$1=25;
}
if($row) {
sleep(10);
} else {
$done=1;
}
}
(I haven't tested that, it might have an error.)