I am trying to send an email to multiple address with php script. I can send an email to multiple addresses. But what I dont want is no recipient can see other recipient's address.
For example I would like to send an email to 2 users (abc.gmail.com & firstname.lastname@example.org) now when i send an email to both these addresses, I dont want any of them to know that I have send the same email to other address too..
I dont want any BCC or CC. Kindly Please Help Me Out Anyone:rolleyes::rolleyes:
Just send them individually, with a foreach loop.
Your problem needs BCC.
Without this header, you cannot "hide" some of the recipients just like that.
Thanks For your Reply, Sorry But I am kind of new to PHP and would like to know how to add BCC in header, as I have tried few different ways, its not working. Thanks
If you use BCC you will still need a TO address which everyone will see. You could have the TO be the same as the FROM but to some people that is suspicious. How to do this depends on what you're using to send them. If you're just using PHP's built in mail() function, look at the additional_headers parameter. http://php.net/mail
If you don't want that you will just have to loop through and send each one a separate email.
Once the email is submitted to be sent it gets sent as an individual email to each recipient regardless. Setting it up with toa loop over all the email addresses with the loop changing theTo address and sending the email to that recipient results in exactly the same number of emails being sent as if you put one of the recipients in the To address and the rest in BCC. If you put all of them in BCC and use the from address or a dummy address as the To address you end up sending one more email than if you use a loop with the To address.
It's less efficient (codewise, at least) but you can use mail() multiple times to send the email to different people. E.g.
mail ($email1, $subject, $body, $header);
mail ($email2, $subject, $body, $header);
mail ($email3, $subject, $body, $header);
Ok, so. There are few things to understand:
1. When you add BCC with lots of emails, the email server will consider that you sent one (and only one) email. Why do you care about this?
2. Some hosts will not allow sending more than [x] emails per hour, where [x] may be 200 or a bit more (again, some hosts! ask at support about yours). If you need to send a newsletter, sending (example) 2000+ emails at once may get your account blocked. So, the BCC can help you a lot because you can split the number of emails to send into chunks and deliver all at once, without exceeding the limit.
3. To send emails with BBC you will have [TO]:email@example.com - [BCC]:firstname.lastname@example.org,email@example.com. So, do not have [TO]:george and [BCC]:mike,jhon because mike and jhon will see the email of george.
4. The best way of sending emails is to add all with [TO] and send multiple emails. If you do not exceed any limitation (as I said, talk with your hosting support) this is the best way - (as ralph.m said and also QMonkey - it's the same thing, different approaches).
Some code, from the manual with some adjustments
$to = 'firstname.lastname@example.org';
// also define your $subject and $message
// how to send an email with BCC
$headers = 'MIME-Version: 1.0' . "\\r\
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\\r\
// this email may not exist
$headers .= 'To: Website <email@example.com>' . "\\r\
// this is a good email, that must exist (some user may send a reply)
$headers .= 'From: Website <goodExistingEmail@website.com>' . "\\r\
// mails to be delivered to
$headers .= 'Bcc: firstname.lastname@example.org,email@example.com,firstname.lastname@example.org' . "\\r\
// Mail it
mail($to, $subject, $message, $headers);
Who have helped me lot, Thank you so much for your time and Concern, my problem is solved with using logic .. i did was made 2 different "TO" variables and typed mail() twice giving both individual variables.
$success = mail($to,$emailSubject,$body,$headers);
$success = mail($to1,$emailSubject,$body,$headers);
Use this code..
$to = "email@example.com,firstname.lastname@example.org";
$headers1 = "MIME-Version: 1.0" . "\\r\
$headers1 .= "Content-type:text/html;charset=iso-8859-1" . "\\r\
$headers1 .= "From: email@example.com\\r\
$content1.="<table width='100%' border='1'>
<tr><td>Your Name </td> <td>kewal knojiya </td></tr>
No it doesn't - each gets sent as a separate email. If you have lots of BCC you are sending lots of individual emails. Hosts are not going to be stupid enough to allow you to send out millions of spam emails just because you BCC the recipients. Each and every email address specified in TO, CC and BCC counts as an email when determining how many emails you are sending.
Each BCC counts as one email so it doesn't help at all. What you have to do is to use a CRON job to send them a few at a time - so with a 200 email per hour limit and 2000 emails to send you spread them over say 12 hours.
This results in sending one more email when you use BCC than when you send them all separately if you use a TO address that is a dummy in order to not expose anyone's email address. So if you do have a limit then you can save one email per send by sending separately and not using BCC.
Definitely since it involves sending one less email and so helps to keep you under any limits
It is true, I did a mistake.
About the counting, it depends on the server configuration.
That extra email is not the reason of "why is better to send individual emails".
And you know that. Anyway, you made your point
This topic is now closed. New replies are no longer allowed.