mail() will not run queries, you need to look at the php manual for the set
of functions for the database type you plan on using and execute the
database stuff in your script and pass the formatted results in the
appropriate argument of the mail function.

$con = mysql_connect($host, $user,$pw);
$query = "SELECT Email from EmailDatabse.TableToUse Where criteria =
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)){
        $bcc .= $row[Email].",";
$bcc = substr($bcc 0, -1); //getting rid of last comma

$headers .= "bcc: $bcc\r\n";

This is just a quick example, you'll need to add error checking and make
sure the argument order is correct on the functions, I don't have time to,
but I thought I'd at least put an effort into sending you on your way to
getting a functioning script.

-----Original Message-----
From: JeRRy [mailto:[EMAIL PROTECTED]
Sent: Monday, March 31, 2003 3:05 PM
Subject: [PHP-DB] PHP mail() question?


I am trying to get PHP mail() to do the following:

1) Grab email addresses from a database and put in the
BCC of the email. (hidding their email address)

2) Grab first names from a database and put in the
body of the email.

Below is a script I am using, does not do any queries
to any database because I am not sure how to do it in
the function.  I have tried but have failed so thought
I'd ask here.  Can anyone help?  Here is the code I am


$myname = "Me Myself";
$myemail = "[EMAIL PROTECTED]";

$contactname = "Mister Contact";
$contactemail = "[EMAIL PROTECTED]";

$message = "hello from ".$contactname."";
$subject = "A email";

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html;
$headers .= "From: ".$myname." <".$myemail.">\r\n";
$headers .= "To: ".$contactname."
$headers .= "Reply-To: ".$myname."
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: Just My Server";

mail($contactemail, $subject, $message, $headers);


Maybe I need a different function? If so could someone
show me a example of how it can be achieved please?



P.S. I am using mysql database. - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.

PHP Database Mailing List (
To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to