i'm working on a mailing list script.. i have it so you can customize the email, and it automatically puts everyones names in it so you dont have to write a new email for everyone on your list.. it all works except sending it.. how can i send more than one message at a time?
Here are the bare bones...
$subject = $_POST['subject'];
$message = $_POST['message'];
$fromfriendly = $_POST['fromaddress'];
$tofriendly = $_POST['tofriend'];
if ($subject && $message)
{
$result=mysql_query("SELECT * FROM affiliates", $connection); //Selects all entries from table users
while($query_data = mysql_fetch_row($result)) //Selects the first row of returned results
{
$to = $query_data[9];
$emcode = array("[realname]", "[id]", "[password]", "[email]");
$emreal = array($query_data[8], $query_data[0], $query_data[1], $query_data[9]);
$newmessage = str_replace($emcode, $emreal, $message);
$newsubject = str_replace($emcode, $emreal, $subject);
$newtofriendly = str_replace($emcode, $emreal, $tofriendly);
$newfromfriendly = str_replace($emcode, $emreal, $fromfriendly);
/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
/* additional headers */
$headers .= "To: $newtofriendly\r\n";
$headers .= "From: $newfromfriendly\r\n";
echo ("<br><b>To:</b> $newtofriendly<br><b>From:</b> $newfromfriendly <br><b>Subject:</b> $newsubject <br><b>Message:</b> $newmessage"); //for debugging only
if (mail($to, $newsubject, $newmessage, $headers))
{
echo ("Message Successfully Sent.");
}
else
{
echo ("Message Was Not Sent.");
}
}
}
The first person in line gets an email sent to them but the others fail... are there any "massmail" functions? or a better way to do this? thanks.
Ok, problem solved! thanks guys!