Forum Moderators: coopster

Message Too Old, No Replies

Pulling email address from database for mail()

roadblocked on a simple problem

         

mooger35

5:55 am on Feb 17, 2006 (gmt 0)

10+ Year Member



Maybe it's because it's late or maybe I'm just a newbie (couldn't be) but I'm having trouble with getting all the names from my database into my $to variable.

$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?

mooger35

6:17 am on Feb 17, 2006 (gmt 0)

10+ Year Member



nevermind....

sometimes it is the simplest little things.

type=hidden works wonders for forms.

omoutop

12:18 pm on Feb 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



OR you can try this :

$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'].", ";
}
}

omoutop

12:20 pm on Feb 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



correction to last part of message :

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