Solved

BCC not working

Posted on 2006-10-28
3
813 Views
Last Modified: 2006-11-18
I want to BCC a group of people with PHP.
The following code does not work.
I don't see an error message.

$query = "SELECT email
      from tbl_daily_verse";

$result = mysql_query($query);
# email - BEGIN
      /* Specify your SMTP Server, Port and Valid From Address */
      ini_set("SMTP","mail.scripturememorychallenge.org");
      ini_set("smtp_port","25");
      ini_set("sendmail_from","me@scripturememorychallenge.org");
      
      $to = "me@scripturememorychallenge.org";
      $subject      = "Daily Verse";
      $headers    = "From: me@scripturememorychallenge.org\r\n";            
      
      while ($row = mysql_fetch_assoc($result)) {
            $headers .= "Bcc: " . $row['email'] . "\r\n";
            $mymessage    = "test";
            echo $row['email'];
            echo "<br>";
            }
      mail ($to, $subject, $mymessage, $headers);
# email - END
0
Comment
Question by:M256
  • 2
3 Comments
 
LVL 6

Expert Comment

by:soapergem
ID: 17832039
What you are doing, effectively, is defining multiple "BCC" headers. There can be only one. It should look like this:

    Bcc: email_1@domain.com, email_2@domain.com, email_3@domain.com

What it's doing right now (and this is incorrect), is this:

    Bcc: email_1@domain.com
    Bcc: email_2@domain.com
    Bcc: email_3@domain.com
0
 
LVL 6

Accepted Solution

by:
soapergem earned 50 total points
ID: 17832047
So in order to fix it, you can replace that last while-loop with something like this:

    $bcc = array();
    while ( $row = mysql_fetch_assoc($result) )
    {
        $bcc[] = $row['email'];
    }
    if ( count($bcc) )
    {
        $headers .= 'Bcc: ' . implode(', ', $bcc) . "\r\n";
    }
0
 
LVL 5

Author Comment

by:M256
ID: 17874960
Thanks for your great answer!  Sorry for the delay in responding; I haven't had a chance to verify your answer until now.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question