PHP mail()出错:在additional_header中发现多个或格式错误的换行:如何解决?

时间:2015-10-07 08:13:43

标签: php

此问题已在此处提出:Error with PHP mail(): Multiple or malformed newlines found in additional_header

但我不知道如何解决它。如果我删除额外的br标签,我的电子邮件就会被打乱

这是我的邮件功能:

class email {
    public $acknowledgment = false;
    public $attachment = array();
    public $body = '';
    public $bounday = '';
    public $br = "\n";

public function send() {
        if($this -> from == '' || sizeof($this -> to) == 0) {
            return false;   
        }

        $headers = 'Date: '.$this -> date;
        $headers .= $this -> br;
        $headers .= 'MIME-version: '.$this -> mimeVersion;
        $headers .= $this -> br;
        $headers .= 'From: '.$this -> from;
        $headers .= $this -> br;
        $headers .= 'Return-Path: '.($this -> returnPath == '' ? $this -> from : $this -> returnPath);
        $headers .= $this -> br;

        if($this -> replyTo != '') {
            $headers .= 'Reply-To: '.$this -> replyTo;
            $headers .= $this -> br;
        }

        if($this -> acknowledgment) {
            $headers .= 'Disposition-Notification-To: '.$this -> from;
            $headers .= $this -> br;
            $headers .= 'X-Confirm-Reading-To: '.$this -> from;
            $headers .= $this -> br;
            $headers .= 'Return-receipt-to: '.$this -> from;
            $headers .= $this -> br;
        }

        $headers .= 'Content-Type: multipart/mixed; boundary="'.$this -> boundary.'"';
        $headers .= $this -> br;
        $headers .= $this -> br;
        $headers .= '--'.$this -> boundary;
        $headers .= $this -> br;
        $headers .= 'Content-Type: text/html; charset="'.$this -> charset.'"';
        $headers .= $this -> br;
        $headers .= 'Content-Transfer-Encoding: base64';
        $headers .= $this -> br;
        $headers .= $this -> br;
        $headers .= chunk_split(base64_encode($this -> body));
        $headers .= $this -> br;
        $headers .= $this -> br;

        if(sizeof($this -> attachment) > 0) {
            foreach($this -> attachment as $key => $array) {
                $headers .= '--'.$this -> boundary;
                $headers .= $this -> br;        
                $headers .= 'Content-Type: '.mime :: get($array['extension']).'; name="'.$array['fileName'].'.'.$array['extension'].'"';
                $headers .= $this -> br;
                $headers .= 'Content-Transfer-Encoding: base64';
                $headers .= $this -> br;
                $headers .= 'Content-Disposition: inline; filename="'.$array['fileName'].'.'.$array['extension'].'"';
                $headers .= $this -> br;
                $headers .= 'Content-Location: '.$key;
                $headers .= $this -> br;
                $headers .= $this -> br;
                $headers .= chunk_split(base64_encode(file_get_contents($key)));
                $headers .= $this -> br;
                $headers .= $this -> br;
            }
        }

        $headers .= '--'.$this -> boundary.'--';
        $headers .= $this -> br;

        foreach($this -> to as $value) {
            echo "sending to : $value\r\n";
            mail($value, "hello world", "hellwo");
            mb_send_mail($value, $this -> subject, '', $headers);
        }

        return true;
    }

知道怎么解决吗? 评论//$headers .= $this -> br;会使我的电子邮件无法读取。

0 个答案:

没有答案