Solved

BCC not working

Posted on 2006-10-28
3
814 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

789 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