SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Send Email to Multiple Hidden Recipients

    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 & xyz@gmail.com) 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
    Last edited by TechnoBear; Feb 19, 2014 at 06:36. Reason: Example e-mail delinked

  2. #2
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    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.
    Be nice to nerds. Chances are you'll end up working for one - Bill Gates
    > photos | admin panel

  3. #3
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.
    - Robert

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,836
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,212
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    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);

  7. #7
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by payalbhatt View Post
    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
    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]:noreply@website.com - [BCC]:list@of.emails,that@you.need. 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
    PHP Code:
    <?php

    $to 
    'noreply@website.com';
    // also define your $subject and $message

    // how to send an email with BCC
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    // this email may not exist
    $headers .= 'To: Website <noreply@website.com>' "\r\n";
    // this is a good email, that must exist (some user may send a reply)
    $headers .= 'From: Website <goodExistingEmail@website.com>' "\r\n";
    // mails to be delivered to
    $headers .= 'Bcc: mike@example.com,george@example.com,jhon@example.com' "\r\n";
    // Mail it
    mail($to$subject$message$headers);
    Be nice to nerds. Chances are you'll end up working for one - Bill Gates
    > photos | admin panel

  8. #8
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To all,
    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.
    like below..
    //variables
    $to=("abc@pim.co.uk");
    $to1=("def@pim.co.uk");


    $success = mail($to,$emailSubject,$body,$headers);
    $success = mail($to1,$emailSubject,$body,$headers);

  9. #9
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    66
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Use this code..

    Code:
    <?
    $to = "noreply2@website.com,noreply2@website.com";
    $headers1 = "MIME-Version: 1.0" . "\r\n";
    $headers1 .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers1 .= "From: noreply2@website.com\r\n";
    $content1="<p><h1>Enquiry Now:</h1></p>";
    $content1.="<table width='100%' border='1'>
    <tr><td>Your Name </td>  <td>kewal knojiya </td></tr>  
    </table>";
    $content1.="<p>Regards,</p>";
    $content1.="<p>Ewebtech</p>";
    mail($to,'TEST',$content1,$headers1);
    ?>
    ------------------------------------------------------------------------
    Best Regards,
    Kewal Knojiya
    Kewal | Kanojia | Kewal Kanojia | PHP Web Developer

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,836
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by vectorialpx View Post
    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?
    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.

    Quote Originally Posted by vectorialpx View Post
    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.
    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.

    Quote Originally Posted by vectorialpx View Post
    3. To send emails with BBC you will have [TO]:noreply@website.com - [BCC]:list@of.emails,that@you.need. So, do not have [TO]:george and [BCC]:mike,jhon because mike and jhon will see the email of george.
    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.

    Quote Originally Posted by vectorialpx View Post
    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
    Definitely since it involves sending one less email and so helps to keep you under any limits
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  11. #11
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    No it doesn't - each gets sent as a separate email.
    It is true, I did a mistake.
    About the counting, it depends on the server configuration.

    Quote Originally Posted by felgall View Post
    4. The best way of sending emails is to add all with [TO] and send multiple emails.
    Definitely since it involves sending one less email and so helps to keep you under any limits
    That extra email is not the reason of "why is better to send individual emails".
    And you know that. Anyway, you made your point
    Be nice to nerds. Chances are you'll end up working for one - Bill Gates
    > photos | admin panel


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •