Assign multiple addresses to a BCC in PHP mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Assign multiple addresses to a BCC in PHP mail

Post by simonmlewis »

Code: Select all

$result = mysql_query ("SELECT * FROM stocknotification WHERE title = '$title'"); 
 
        while ($row = mysql_fetch_object($result))
        {
        $to = "info@domain.co.uk";
        $bcc = "        
        $subject =  "New Stock Arrival Notification";
        $headers = "From: info@domain.co.uk";
        $body = "
Dear customer.
 
A Support Email has been assigned to you.
 
Email Reference ID $id.
 
Best regards
COMPANY";
mail ($to, $subject, $body, $headers);   
        }
How can I get this to work?

I have posted something related to this query already, but this is different. I have a number of rows with the same title, but different email addresses. I want to query the db table, and assign the email address into one $bcc, so ONE email can go out, without going thru a loop and sending 200+ emails.

Anyone know a way, coz I have thought "outside the box" but cannot come up with the answer.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Assign multiple addresses to a BCC in PHP mail

Post by simonmlewis »

Code: Select all

$result = mysql_query ("SELECT * FROM stocknotification WHERE title = '$title'"); 
 
        while ($row = mysql_fetch_object($result))
        {
        $emails = ($emails += $row->email += ",");
        $url = $row->url;
        $titlename = $row->title;  
        }
        mysql_free_result($result);
        
        $to = "info@domain.co.uk";
        $bcc = "$emails";
I wonder if this is getting close, though I think the += method is for adding in mathematics not putting a load of email addresses together.

I need a way to put all the addresses together so they'll work in a $bcc.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply