Link to home
Start Free TrialLog in
Avatar of sam85281
sam85281

asked on

Mail() hide "to:" addresses?

Here's my mail code:
<?php
$mailthis = stripslashes($_POST['htmlCode']);
$mailList = str_replace("\r\n",'',implode(',',file('maillist.txt')));
$mailList = stripslashes($mailList);
$email = "mail@mail.com";
$Subject = "Mail list test";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $email\r\n";
mail("$mailList", stripslashes($Subject), $mailthis, $headers);
?>

All works fine, but it's sending to a mail list and I don't want the recipient to get the list of addresses in the header.

How can I hide all those addresses from showing up on the recipient's end?

I tried using:
$headers .= "Bcc: $mailList";
But it only sent to the first address in the list and then placed all the rest of the addresses in the body???

Any clues?

Thanks,
-Sam
Avatar of danny_ebbers
danny_ebbers

Hi sam85281,
> ut it only sent to the fir

try implode with ; instead of ,

Best regards,
Danny Ebbers
Avatar of Kani Str
I tell you the flow you need to do this...
1) get all the email addresses
2) split them and put it in an array.
3)sent it individually...
4)So no one else can see the email address of other

this is like you have a text file like
email1@yahoo.com,email2@yahoo.com,email1@yahoo.com,email1@yahoo.com,
split these and put it in an array like
arr[0]=email1@yahoo.com
arr[1]=email2@yahoo.com
arr[2]=email1@yahoo.com
.
.

then sent it running a loop..
That's it
ASKER CERTIFIED SOLUTION
Avatar of Promethyl
Promethyl
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The BCC Header

The BCC header works like the CC header, indicating that the message is to be copied to all the addresses on this list, except that this is a blind copy: the recipients aren't supposed to know who else the message is being copied to. This means that the server is supposed to strip out the BCC header before delivering each copy of the message. Only the sender gets to see the contents of this header. But remember that nothing is truly private or secure on the Internet unless it's sent end-to-end by encrypted protocols; just because you cause the messages to omit mention of the other recipients doesn't mean that somebody, somewhere, won't purposely or accidentally discover who you sent the message to. If there are bad addresses on the list, for instance, the message might get bounced to the server's postmaster.

In addition to privacy and security, the BCC style of sending is sometimes used when sending to long lists of addresses in order to prevent the headers from being longer than the message itself, wasting bandwidth and disk space and (in some mail readers) forcing a lot of scrolling down to get to the actual message content. Also, if one of the recipients selects "Reply To All" when responding, the reply would go to everybody on the list if they're in a normal To or CC header, but not in a BCC header (because the recipient doesn't even have that header to send to). I've been an unfortunate recipient of cascades of messages that result when something unexpected is sent to a long list, some of whom "Reply To All" to complain that the first sender is "spamming" them, causing more unexpected messages for all the other recipients, some of whom "Reply To All" in turn. That can be really unpleasant.

Source: http://mailformat.dan.info/headers/from.html
> Oh, and I converted the formatting to Linux. Assumed you were not on a Windows box.

RFC 2822 says that headers should be separated by \r\n. It's not platform dependent. Line breaks in bodies are a different matter.

I'd strongly recommend using PHPMailer (phpmailer.sourceforge.net) instead of plain mail(). It gets all these things right without you having to remember it all.

Many mail gateways will reject a message which contains only BCC recipients - you must always supply a To header as well. In countries with very strong data protection laws, such as Germany and Spain, I'd advise you not use BCC at all, and send every message separately.
I did include a TO:. I sent it to myself. =)

It was my understanding the DOS style line breaks were optional. Good info.

I didn't mean that you didn't include one, just that it's a good idea to do so - it's quite common for users to try leaving it out, and then wonder why it all bounced. Technically it should work, but practically it tends not to.

Sections 2.1 and 2.2 cover line breaks: http://www.faqs.org/rfcs/rfc2822.html
Avatar of sam85281

ASKER

Hi, sorry I haven't checked out and closed this yet.  I got side tracked on another project.

I'm back on this one now, so I'll see what works here and get it wrapped up today.

-Sam