i have quite a few email functions which works in that way for administration areas for clients.
all database driven though.
Anyways, you'll get the general idea of what to do with it.
<?
$sql = "Select all the emails from table";
$result = pg_exec($conn,$sql);
$num = pg_numrows($result);
if ($num != 0)
{
for ($i=0; $i<$num; $i++)
{
$myrow = pg_fetch_array($result, $i);
//Email address is added to mailRecipient
$mailRecipient = $myrow['emailAddress'];
//Email message is added to mailMessage
//Could be from a form or set in the
//script
$mailMessage = $message;
//Subject name is added to Subject
$mailSubject = "Domain Updates";
//From line is added to Header
$mailHeader = "From: crew@stereotypography.com";
//mail() function is completed and email is
//sent to individual recipients.
mail($mailRecipient, $mailSubject, $mailMessage, MailHeader);
}
}
else
{
echo "No email addresses available!";
}
If you're using a different database than PostgreSQL then just exchange the pg with mysql for example.
If you're using a textfile i'd advise you to change that to a database instead (email addresses are personal information and shouldn't really be stored in text files).
Anyways, to get the email count in the text file for use in the for loop just do this.
$fp = fopen($txtfile, "r");
$num = 0;
while (!feof($fp))
{
$ff = fgets($fp, 5000); $num++
}
Anyways, hope this was of some small help, if not then just let me know..cheers