向多个收件人发送电子邮件 - 抄送:和密送:在PHP中

时间:2010-10-07 05:01:30

标签: php email

此程序正在运行,但如何发送多个CC和BCC。

for($i = 0; $i < count($snteadd); $i++)
{
    $subjt    = $subject;
    $mess     = $message;
    $toinfo  .= $snteadd[$i];
    $headers  = "MIME-Version: 1.0 \r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "from: <$fromemailid>\r\n";
    $headers .= "Reply-To: <$fromemailid>\r\n";  
    $hedders .= "cc : <$sendCC>\r\n" ; 
    $headers .= "Bcc :  <$sendBCC>\r\n";
    $headers .= "X-Mailer: PHP 4.x";         
    $sendbcc = $snteadd[$i] .",";
    $sendbcc .= $sendCC . ",";
    $sendbcc .= $sendBCC;             

    if($jvl != $i) 
    {
        $toinfo .= ", ";
    }

    if($snteadd[$i] != "") 
    {
        $result = mail($sendbcc, $subjt, $mess, $headers);
        if(!$result)
        {     
            $subjdis     = "Auto Response for Message Sending Failed";
            $headersdis  = "MIME-Version: 1.0\r\n";
            $headersdis .= "Content-type: text/html; charset=iso-8859-1\r\n";
            $headersdis .="Message Sending Failed\r\n";
            $headersdis .= "From: <$fromemailid> \r\n";
            $msgdis = "Message Could not be Delivered to this Mail ID ".$snteadd[$i];
            mail($fromemailid, $subjdis, $msgdis, $headersdis);   
            print "We encountered an error sending your mail <br>";
            //echo $headersdis;
        }
    }
}

1 个答案:

答案 0 :(得分:14)

只有以逗号分隔的地址列表才能为每个字段执行操作。请注意,您的问题代码中有很多拼写错误。