hello all.
i have this simple script to send emails to my subscribers. i've broken the sending into 20 emails per batch to get around getting a timeout error in my browser. without bias from using PEAR in sending multiple emails, any comments to improve the code will be appreciated. thank you.
<?php
include("user_functions.php");
include("connection.php"); // connects to MySQL database
$allsent = false; // flag to signal that message has been sent to all subscribers
$subject = "email subject";
$message = "Content of the Email message.";
$headers = "From: name@domain.com";
// send email 20 at a time
$query = "SELECT * FROM email_database WHERE sent != 1 LIMIT 20";
$result = mysql_query($query, $conn);
if (mysql_num_rows($result) > 0) {
while ($rows = mysql_fetch_assoc($result)) {
mail ($rows['email'], $subject, $message, $headers);
$query2 = "UPDATE email_database SET sent = 1";
$result2 = mysql_query($query2, $conn);
}
} else {
$allsent = true;
}
include("close_connection.php"); // close the connection
for ($i=0; $i<=1000000; $i++) {
//delay counter
}
if !$allsent {
redirect_to( self ); // user defined function (header function)
}
?>