Solved

BCC not working

Posted on 2006-10-28
3
817 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

739 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