View Full Version : mail function with list inside text file

09-06-2009, 05:29 AM
I have a few text files that include a few hundred email addresses each separated by new lines. I need to use the mail() command to send a separate email to each email. I know how to do this using a database, but I can't figure out how to with fopen(), if that's even what i'd use. Anyone know how this could be done?

PS: The code below is what I use for a database, need something that does the same with a text file.

$result = mysql_query("select * from users order by uId");
//grab all the content


if ($error == "") {
mail($send,$subject,$body,"From:$aemail\nContent-Type: text/html; charset=iso-8859-1");

echo "<div align=center>email sent to:$send<Br></div>";

The PHP Guy
09-06-2009, 10:24 AM
Try this:

<div align="center">
Email sent to:<br>
$list = file('email-list.txt');
foreach($list as $email)
mail($email, $subject, $body, "From:$aemail\r\nContent-Type: text/html; charset=iso-8859-1");
echo "$email<br>";

09-06-2009, 12:17 PM
Thank you so much! The code works perfectly, you are truly a life saver =]