2013-07-15 65 views
7

我爲我的網站使用Codeigniter 2。當向多個用戶發送電子郵件時,在客戶端(gmail,hotmail,..)上顯示所有地址的詳細信息,如何隱藏地址以顯示接收方地址。用codeigniter發送多封郵件

感謝

回答

17

使用BCC發送批量電子郵件這樣的:

function batch_email($recipients, $subject, $message) 
{ 
    $this->email->clear(TRUE); 
    $this->email->from('[email protected]', 'Display Name'); 
    $this->email->to('[email protected]'); 
    $this->email->bcc($recipients); 
    $this->email->subject($subject); 
    $this->email->message($message); 

    $this->email->send(); 

    return TRUE; 

} 

$收件人應該是一個逗號分隔的列表或數組

這意味着你將獲得電子郵件,但所有其他的副本收件人將被bcc'ed,所以不會看到對方的地址

+11

我並不總是回答問題,但是當我這樣做時,發佈它的用戶不會回來告訴我是否有幫助:-( – whispersan

+0

謝謝@whisperson先生!這節省了我一段時間...並且工作like charm! –

+0

我希望我能找到一個關於codeigniter密件抄送的好的綜合教程,我似乎無法讓密件抄送工作,並且我嘗試了逗號分隔的列表和數組。 – TARKUS

6

我認爲你是分配的所有收件人在一個單一的方法,像

$this->email->to('[email protected], [email protected], [email protected]'); 

這將立即郵寄給所有收件人。爲了防止顯示所有收件人,分別郵寄爲每個用戶,如下,

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

這裏$list包含收件人姓名和電子郵件ID的數組。確保在每次迭代開始時使用clear()

+0

好像你不應該發送單獨的電子郵件給每個收件人,當這是密件抄送應該做的。 – TARKUS