Solved

BCC not working

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now