Page 1 of 2

Using BCC in email header doesn't work?

Posted: Sun Oct 06, 2002 9:11 am
by Matt Phelps
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.....

Code: Select all

$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?

Posted: Sun Oct 06, 2002 10:45 am
by Takuma
How did you format the senders on bcc? comma separated or ; sperated? I think it should be separated by commas like so:-

Code: Select all

<?php
mail("to","subject","message","BCC: mail1,mail2");
?>

Posted: Sun Oct 06, 2002 10:56 am
by Matt Phelps
Yep - they are already comma delimited. So it would be someone@email.com,someoneelse@anotheremail.com etc etc
:(

Posted: Sun Oct 06, 2002 10:59 am
by Takuma
Try removing "\r\n" so it'll be like

Code: Select all

<?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"; 
?>

Posted: Sun Oct 06, 2002 11:15 am
by Matt Phelps
Well without the /r/n tags it doesn't work at all. Can the BCC functionality be removed by the webhost? Maybe to stop people spamming or something?

Posted: Sun Oct 06, 2002 12:12 pm
by Takuma
Mmmm You're right, if you're host is using UNIX type OS they probably use sendmail. And I don't think you can restrict it ut anyway...

How aout this code?

Code: Select all

<?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"; 
?>

Posted: Sun Oct 06, 2002 2:10 pm
by twigletmac
From the manual entry on mail()
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.

Mac

Posted: Sun Oct 06, 2002 2:44 pm
by Matt Phelps
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?

Posted: Mon Oct 07, 2002 1:30 am
by Takuma
does this work?

Code: Select all

&lt;?php
mail("address1,address2,address3","subject","message");
?&gt;

Posted: Mon Oct 07, 2002 1:41 am
by Matt Phelps
Well I think it would but then everyone's address would be in the TO field and be viewable by everyone else who recieves the newsletter.

Posted: Mon Oct 07, 2002 1:49 am
by Takuma
Well you could do this then...

Code: Select all

&lt;?php
while(blah blah) {
  mail("","","","");
}
?&gt;

Posted: Tue Dec 24, 2002 8:28 am
by Matt Phelps
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.

Posted: Fri Dec 27, 2002 3:21 pm
by Matt Phelps
Nobody has a clue? :(

Posted: Fri Dec 27, 2002 5:07 pm
by evilcoder
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.

Posted: Sat Dec 28, 2002 6:57 am
by Matt Phelps
Right okay. I'm screwed then. :( Sending 100 emails seems like a very server intensive way of doing it.