Using BCC in email header doesn't work?

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!

Moderator: General Moderators

Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Using BCC in email header doesn't work?

Post 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?
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post 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");
?>
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post by Matt Phelps »

Yep - they are already comma delimited. So it would be someone@email.com,someoneelse@anotheremail.com etc etc
:(
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post 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"; 
?>
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post 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?
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post 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"; 
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post 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?
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

does this work?

Code: Select all

&lt;?php
mail("address1,address2,address3","subject","message");
?&gt;
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post 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.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Well you could do this then...

Code: Select all

&lt;?php
while(blah blah) {
  mail("","","","");
}
?&gt;
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post 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.
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post by Matt Phelps »

Nobody has a clue? :(
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post 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.
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post by Matt Phelps »

Right okay. I'm screwed then. :( Sending 100 emails seems like a very server intensive way of doing it.
Post Reply