This is just a skeleton outline of one way you might build a simple mass mailer with PHP. You would need to add more error_handling, but you should get the idea.
<?PHP
//do your connect and database select here and store it as $db
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Me <me@me.com>\r\n";
if ($email_to == 'all') {
$sql = "SELECT field1 FROM table1";
@ $result = mysql_query ($sql, $db);
while ($row = mysql_fetch_array($result)) {
if (@mail($row['EMAIL'],$subject,$mesg,$headers))
$success ++;
else {
// you should add some code here to pause and/or retry if it fails
$failure ++;
}
}
echo 'Successes: ' . $success . '<br>';
echo 'Failures:' . $failure . '<br>';
$timeparts = explode(" ",microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
$exec_time = bcsub($endtime,$starttime,3);
echo 'Script execution time ' . $exec_time . ' seconds.';
}
?>
Hope this helps 😉