gatorix
gatorix

Reputation: 31

Hide other recipients

I have a mailer function, which sends mail to recipients extracted from database. How can I hide other recipients? BCC doesn't work. Mailer source:

$to=array();
while($row = mysql_fetch_array($subscrquery)) {
    array_push($to, $row['subscr_mail']);
}
$msgheader=$ttl;

$mailheaders  = "MIME-Version: 1.0\r\n";
$mailheaders .= "Content-type: text/html; charset=UTF-8\r\n";
$mailheaders .= "From: ".$sender." <".$sender.">\r\n";
$mailheaders .= "Reply-To: ".$sender." <".$sender.">\r\n";
$mailheaders .= "Bcc: ".implode(',', $to)."\r\n";           
$mailmsga .= stripslashes($mailcontent);
$mailmsg .= strtr($mailmsga, array("<" => "\n<"));
mail(implode(',', $to), $msgheader,$mailmsg,$mailheaders);

Upvotes: 0

Views: 1288

Answers (3)

Kevin Nelson
Kevin Nelson

Reputation: 7663

Typically, you want to send one e-mail message per recipient. Sending BCC will make it more likely that you get filtered by spam filters.

If your list is large, then you'll want to avoid using PHP's built-in mail method because it opens and closes a connection for every single e-mail. Instead, you should use an SMTP e-mailer that will only open one connection for all the e-mails that get sent. Possible options:

  • the (probably outdated) PEAR package has an SMTP mailer
  • Zend\Mail\Transport\Smtp is a more up-to-date namespaced package

Most larger frameworks, like Zend, probably have their own SMTP mailer as well.

In general, it is a good idea to use an existing package so that you don't have to worry about header injections, maximum line-lengths for e-mails, etc.

Upvotes: 3

zohaib
zohaib

Reputation: 1

Simply add this line

$headers .= 'To:  Unknown<undefined>' . "\r\n";

Upvotes: 0

gcochard
gcochard

Reputation: 11744

There's a problem on your last line:

mail(implode(',', $to), $msgheader,$mailmsg,$mailheaders);

Right there, you're sending the email "to" everyone. The BCC handles that already. Use a bogus address (or your address, or whatever) in the first argument to mail, and it should fix the problem. The last line SHOULD read something like this:

mail('[email protected]', $msgheader,$mailmsg,$mailheaders);

Upvotes: 1

Related Questions