2013-01-09 28 views
19

如何製作密送郵件? 如果我發送該郵件,它會向我顯示所有收件人!php mail密送多收件人

$to=array(); 
$members_query = mysql_query("select email from members"); 
while($row = mysql_fetch_array($members_query)) 
{ 
    array_push($to, $row['email']); 
} 

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; 

// Additional headers 
//$headers .= 'To: '.$newName.' <'.$newEmail.'>' . "\r\n"; 
$headers .= 'From: SmsGratisan.com <[email protected]' . "\r\n"; 


mail(implode(',', $to), $title, $content, $headers); 

謝謝!

+0

您需要添加一個BCC頭與收件人列表。有關示例,請參見[手冊](http://php.net/manual/en/function.mail.php)。 –

回答

24

設置你的mail到現場來null,然後爆你的$to陣列在你的頭

$headers .= 'From: SmsGratisan.com <[email protected]' . "\r\n"; 
$headers .= 'BCC: '. implode(",", $to) . "\r\n"; 


mail(null, $title, $content, $headers); 
-1

請使用經過剛纔陣列,而不是做任何形式的內爆,集行情,逗號等。

實施例:

$bcc = array(); 

    foreach ($users as $user) 
    { 
     $bcc[] = $user['User']['email']; 
    } 

而且它傳遞給Mail功能:

 $email->from($from) 
//   ->to($from) 
       ->bcc($bcc) 

感謝, ANKIT帕特爾

相關問題