[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 828
  • Last Modified:

BCC not working

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 */
      $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
  • 2
1 Solution
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
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";
M256Author Commented:
Thanks for your great answer!  Sorry for the delay in responding; I haven't had a chance to verify your answer until now.

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now