Forum Moderators: coopster
I am having issues trying to write a simple newsletter script, this is what I have so far:
<?php
//get the variables
$subject = $_POST['nform_newsltitle'];
$message = $_POST['nform_newsltext'];
$recipients = $_POST['nform_newslrecipients'];
$email = "contact@example.com";
//if ALL and SPECIFIC users have been selected, go back to the form with an error
if ($recipients[0] == "ALL" && strlen($recipients[1]) > 1) {
$link = 'Location: index.php?page=writenewsletter&newsl_error=1&newstitle='.$title.'&newsltext='.$text;
header($link);
} else {
//include our db data to make the connection
include ('db.php');
if ($recipients[0] == "ALL") {
$content1 = mysql_query("SELECT email FROM users WHERE newsletter = 1");
while($row = mysql_fetch_array($content1))
{
$to = $row['email'].',';
echo $to;
}
} else {
}
mail($to,$subject,$message,"From: ".$email.""); //a very simple send
?>
But it's only sending one email and ignoring the other recipients.
Any experienced users know what I am doing wrong?
Thank you!
$addresses = array();
while($row = mysql_fetch_array($content1))
{
addresses[] = $row['email'];
}
and then:
if (!empty($addresses)) {
mail(implode(',',$addresses),$subject,$message,"From: ".$email."");
}
dc