7

I'm using Codeigniter 2 for my website. When send email to multiple users , on client( gmail, hotmail,..) it shows all addresse on details , how can i hide the addresses to show just the receiver address.

Thanks

Nabil Lemsieh
  • 716
  • 4
  • 11
  • 27

2 Answers2

17

Use bcc to send batch emails like this:

function batch_email($recipients, $subject, $message) 
{
  $this->email->clear(TRUE);
  $this->email->from('you@yoursite.com', 'Display Name'); 
  $this->email->to('youremailaddress@yourserver.com');
  $this->email->bcc($recipients);
  $this->email->subject($subject);
  $this->email->message($message);  

  $this->email->send();

    return TRUE;

}

$recipients should be a comma-delimited list or an array

It means that you will get a copy of the email but all other recipients will be bcc'ed, so won't see each other's addresses

whispersan
  • 1,029
  • 2
  • 13
  • 28
  • 11
    I don't always answer questions, but when I do, the user who posted it doesn't come back to tell me if helped :-( – whispersan Jul 25 '13 at 21:44
  • thanks @whisperson Sir!.. this save me a time... and works like charm! – Mohammed Sufian Feb 26 '14 at 15:36
  • I wish I could find a good, comprehensive tutorial on codeigniter bcc. I just can't seem to get the bcc to work, and I have tried comma delimitted lists and arrays. – TARKUS Nov 23 '16 at 20:46
7

I think you are assigning all recipients in a single to method, like

$this->email->to('one@example.com, two@example.com, three@example.com');

This will mail to all recipients at once. To prevent showing all recipients, mail it separately for each user, as follows,

foreach ($list as $name => $address)
{
    $this->email->clear();
    $this->email->to($address);
    $this->email->from('your@example.com');
    $this->email->subject('Here is your info '.$name);
    $this->email->message('Hi '.$name.' Here is the info you requested.');
    $this->email->send();
}

Here $list contains array of Recipient name and email ID. Make sure to use clear() at the beginning of each iteration.

Saravanan
  • 1,879
  • 2
  • 27
  • 30
  • Seems like you shouldn't have to send separate emails to each recipient, when that's what the bcc is supposed to do. – TARKUS Nov 23 '16 at 20:47