简体   繁体   中英

Sending an Email to Multiple Recipients - Cc: and Bcc: in php

This program is running but how to send multiple CC and 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;
        }
    }
}

Just a comma-separated list of addresses should do for each field. Note that you have a number of typo's in the code in your question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM