PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Can anyone spot what I am doing wrong here? I am trying to send a newsletter to a bunch of subscribers without sending out everyone's email address as well - so I want to use the BCC field in the email header. The variable $subscribers is a list of email addresses seperated by a comma (not a semi-colon because I'm told that the mail function wouldn't like that) and then passed to the mail() function below.
The problem is that nobody on the BCC list gets the email - only the person in the TO field gets the email.....
$email_to = "subscribers@mywebsite.net";
$email_title = "$month Newsletter";
$email_header = "MIME-Version: 1.0\r\n";
$email_header .= "Content-type: text/html; charset=iso-8859-1\r\n";
$email_header .= "From: news@mywebsite.net\r\n";
$email_header .= "Bcc: $subscribers\r\n";
//then finally the actual sending of the email including a message which I have defined elsewhere//
if (mail($email_to, $email_title, $email_message, $email_header))
echo "Newsletter sent to subscribers";
Is it something in the header that I'm not doing right? Why doesn't BCC work here?
<?php
$email_to = "subscribers@mywebsite.net";
$email_title = "$month Newsletter";
$email_header = "MIME-Version: 1.0;";
$email_header .= "Content-type: text/html; charset=iso-8859-1;";
$email_header .= "From: news@mywebsite.net;";
$email_header .= "Bcc: $subscribers;";
//then finally the actual sending of the email including a message which I have defined elsewhere//
if (mail($email_to, $email_title, $email_message, $email_header))
echo "Newsletter sent to subscribers";
?>
<?php
$email_to = "subscribers@mywebsite.net";
$email_title = "$month Newsletter";
$email_header = "MIME-Version: 1.0\r\n";
$email_header .= "Content-type: text/html; charset=iso-8859-1\r\n";
$email_header .= "From: news@mywebsite.net\r\n";
$email_header .= "Bcc: $subscribers";
//then finally the actual sending of the email including a message which I have defined elsewhere//
if (mail($email_to, $email_title, $email_message, $email_header))
echo "Newsletter sent to subscribers";
?>
The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine). Second the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP. PHP < 4.3 only supported the Cc: header element (and was case-sensitive). PHP >= 4.3 supports all the mentioned header elements and is no longer case-sensitive.
Just in case you might be using Windows. If you're on a *nix host you could try using just \n instead of \r\n.
Ahh nuts. My host is running PHP 4.1.2. Guess that's why Bcc isn't supported. I'll have to find another way to do this I guess. Any suggestions for way of sending out a bulk email without revealing everyone's email address?
Sorry I don't get what you mean by that? You mean loop around for each address? An individual email for each person? I'd rather not have to send 60/70 emails out - I want to send just one.
Without Bcc capabilities the To: field is the only way of sending, which means you either send showing all the email addresses or your send indiviually using a loop.