The following code will keep sending mails until all rows (that match the criteria) are processed.
$query = mysql_query("SELECT theEmailAddress FROM tablename WHERE 1");
while ($row = mysql_fetch_assoc($query)) {
$to = $row['theEmailAddress'];
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
Most mailservers are however blocking the php mailer, or mark it as spam. So I'd recommend looking into an SMTP mailer class. There are a lot of different types, so you will have to pick one yourself. But then you can connect to a gmail (or other SMTP account) and have your mail sent through there. It makes things more reliable.