【问题标题】:PHP mail BCC multiple recipients not sending to BCCPHP邮件密件抄送多个收件人未发送到密件抄送
【发布时间】:2015-12-19 16:29:34
【问题描述】:

我正在尝试发送电子邮件的密件抄送(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";
    }
}

发送电子邮件时,收件人会收到电子邮件,但密件抄送收件人不会。


感谢 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";
    }
}

【问题讨论】:

  • 用分号分隔电子邮件地址;不是逗号,
  • 坚持我的 nl ​​函数没有返回。这可能是我的问题..让我试试
  • @Dave 哦,我以为你可以使用逗号
  • 我一直用; (好吧,直到我换成使用 swiftmailer,因为它更好)也 Bcc 应该是 BCC 我相信电子邮件标题区分大小写。
  • @Dave 谢谢!有效。发布答案并让您成为最佳答案

标签: php email


【解决方案1】:

我认为密件抄送在电子邮件标题中区分大小写,因此应该是密件抄送:不是密件抄送:还认为密件抄送电子邮件地址需要用 ; 分隔

虽然我个人也建议换成适当的邮件组件,例如 swiftmailer,它可以为您提供比内置 php mail() 函数更好的错误报告/捕获和功能

【讨论】:

  • 嗯,我要收藏这篇文章,以便以后参考。我将来可能会升级到 swift mailer :)
猜你喜欢
  • 2012-12-23
  • 2013-12-22
  • 2012-03-20
  • 1970-01-01
  • 2020-10-10
  • 2015-01-01
  • 2014-05-23
  • 1970-01-01
相关资源
最近更新 更多