php mail bcc multiple recipients

蹲街弑〆低调 提交于 2019-11-27 03:47:41

问题


How do I make a bcc mail? If I send that mail, It shows me all the recipients!

$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 <admin@website.com' . "\r\n";


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

Thanks!


回答1:


Set your mail to field to null, and then implode your $to array in your headers

$headers .= 'From: SmsGratisan.com <admin@website.com' . "\r\n";
$headers .= 'BCC: '. implode(",", $to) . "\r\n";


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



回答2:


$headers .= 'Bcc: mail@example.com' . "\r\n";



回答3:


CC and BCC can be sent as headers (see: http://php.net/manual/en/function.mail.php).

You can also use other mail libraries - the PEAR Mail library makes sending emails a little more object-oriented. http://pear.php.net/package/Mail/redirected




回答4:


Please use pass Just Array instead of doing any kind of Implode, Set quotes, comma etc.

Example:

    $bcc = array();

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

And pass This To Mail Function:

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

Thanks, Ankit Patel



来源:https://stackoverflow.com/questions/14238207/php-mail-bcc-multiple-recipients

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!