Forum Moderators: coopster
$sql_mail = "SELECT email
FROM players
WHERE email!= 'none'";
$result_mail = mysql_query($sql_mail);
//bunch of error message validation stuff...
//fetch email addresses from query
while($row_mail = mysql_fetch_assoc($result_mail)){
$to = $row_mail['email'].", ";
}
$subject = $_POST['subject'];
$headers .= "From: Me <email@site.com>\r\n";
$headers .= "Reply-To: email@site.com\r\n";
$message = $_POST['message'] . "\n";
//now before sticking $to in mail() now with my $headers, $subject and $message I figured that if I try that php will only include the first record.
echo $to; //returns first record as I figured.
How do I keep the list of emails from my while without having all the other stuff ($headers etc) repeat with every record?
$to="";
$sql_mail = "SELECT email
FROM players
WHERE email!= 'none'";
$result_mail = mysql_query($sql_mail);
//bunch of error message validation stuff...
//fetch email addresses from query
while($row_mail = mysql_fetch_assoc($result_mail)){
$to .= $row_mail['email'].", ";
}
Notice the ($to .=) .... you have forgotten this from your code...
hopefully this will give you something like $to = email1, email2,email3,email4.... (which are visible in the email To address bar). Perhaps you can modify some part of your code to send 1st email to (To) field, and the rest as Bcc?
Try this :
$k=0;
$bcc="";
$sql_mail = "SELECT email FROM players WHERE email!= 'none'";
$result_mail = mysql_query($sql_mail);
//bunch of error message validation stuff...
//fetch email addresses from query
while($row_mail = mysql_fetch_assoc($result_mail))
{
$k++;
if ($k==1)
{
$to = $row_mail['email'].", ";
}
else
{
$bcc .= $row_mail['email'].", ";
}
}
Try this :
$k=0;
$bcc="";
$sql_mail = "SELECT email FROM players WHERE email!= 'none'";
$result_mail = mysql_query($sql_mail);
//bunch of error message validation stuff...
//fetch email addresses from query
while($row_mail = mysql_fetch_assoc($result_mail))
{
$k++;
if ($k==1)
{
$to = $row_mail['email'];
}
else
{
$bcc .= $row_mail['email'].", ";
}
}
Have done a mistype in $to declaration inside while loop :p sorry about that