Reputation: 31
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
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:
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
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