PHP邮件BCC多个收件人没有发送到BCC

时间:2015-09-22 15:42:24

标签: php email

我正在尝试发送电子邮件的BCC(Blind Carbon Copy)。

这是我的班级:

class email{
    function __construct(){
    }
    public function send($to, $from, $subject, $message){
        $header = $this->nl('MIME-Version: 1.0') .
        $this->nl('Content-Type: text/plain; charset=utf-8') .
        $this->nl('X-Priority: 1') .
        $this->nl('Importance: High') .
        $this->nl('X-MSMail-Priority: High') . 
        $this->nl('Bcc: email1@email.com,email2@email.com') .
        $this->nl('X-Mailer: PHP/' . phpversion());
        return mail(
            $to,
            $subject,
            $message,
            $header,
            '-f ' . $from
        );
    }
    private static function nl($str){
        return $str . "\r\n";
    }
}

发送电子邮件时,收件人会收到电子邮件,但 BCC 收件人却没有。

得益于Dave的解决方案:

class email{
    function __construct(){

    }
    public function send($to, $from, $subject, $message){
        $header = $this->nl('MIME-Version: 1.0') .
            $this->nl('Content-Type: text/plain; charset=utf-8') .
            $this->nl('X-Priority: 1') .
            $this->nl('Importance: High') .
            $this->nl('X-MSMail-Priority: High') . 
            $this->nl('BCC: rick <rick@email.com>; angela <angela@email.com>') .
            $this->nl('X-Mailer: PHP/' . phpversion());
        return mail(
            $to,
            $subject,
            $message,
            $header,
            '-f ' . $from
        );
    }
    private function nl($str){
        return $str . "\r\n";
    }
}

1 个答案:

答案 0 :(得分:0)

BCC在电子邮件标题中区分大小写我认为应该是BCC:不是Bcc:还认为bcc电子邮件地址需要分开;

虽然我个人也建议交换到正确的邮件组件,例如swiftmailer,可以在内置的php mail()函数之外提供更好的错误报告/陷阱和功能