Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不同服务器上的PHP Mail+Thunderbird/Outlook呈现错误_Php_Email_Webserver_Phpmailer - Fatal编程技术网

不同服务器上的PHP Mail+Thunderbird/Outlook呈现错误

不同服务器上的PHP Mail+Thunderbird/Outlook呈现错误,php,email,webserver,phpmailer,Php,Email,Webserver,Phpmailer,我要走了 Reply-To: example@example.com X-Mailer: PHP/5.2.12-nmm2 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==Multipart_Boundary_x10392fewe84c0f4df70d308d1c15c5x" Message-Id: <20111206073526.C069ECdf30D@dd18038.xxxxxxx.com> Da

我要走了

Reply-To: example@example.com

X-Mailer: PHP/5.2.12-nmm2
MIME-Version: 1.0

Content-Type: multipart/mixed;
  boundary="==Multipart_Boundary_x10392fewe84c0f4df70d308d1c15c5x" 

Message-Id: <20111206073526.C069ECdf30D@dd18038.xxxxxxx.com>
Date: Tue,  6 Dec 2011 08:35:26 +0100 (CET)
Return-Path: <www-data@example.com>



--==Multipart_Boundary_x10392fewe84c0f4df70d308d1c15c5x
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Test Message <h1>Html Content</h1>
这是在使用php邮件时发生的。相同的脚本在我的其他服务器上运行良好,但在另一个服务器上出错。所有服务器都是基于Linux的

这里的问题是什么

编辑:1


我不确定你的问题到底是什么。这是您的头被破坏的原因吗?它们之间不应该有空行,还是在一台服务器上出现错误的原因?对于前者,我们需要一个代码片段,对于后者,错误消息代码正在我的测试服务器上工作,而在部署服务器上不工作。我将添加源pls WAIT部署服务器上的错误是什么?该消息显示在我的问题部分的顶部。它不是测试消息Html内容,而是以纯文本显示所有标题
<?php

Class Mailler{


    public $to;
    public $cc;
    public $bcc;
    public $from;
    public $subject;
    public $header;
    public $message;
    public $attach;
    public $type;
    public $replyTo;
    public $fromName;
    public $fromUserName;

    function __construct(){

    }

    function _setTo(){
        if(is_array($this->to))
            return implode(",",$this->to);
        else
            return $this->to;
    }

    function _setCc(){
        if(is_array($this->cc))
        return implode(",",$this->cc);
        else
        return $this->cc;
    }   

    function _setBcc(){
        if(is_array($this->bcc))
        return implode(",",$this->bcc);
        else
        return $this->bcc;
    }

    function _setFrom(){
        if(is_array($this->from))
        return implode(",",$this->from);
        else
        return $this->from;
    }
    function _setFromName(){
        if(!empty($this->fromName)){
        return $this->fromName=$this->fromName.' <'.$this->from.'>';
        }else{
        return $this->fromName=$this->fromUserName.'<'.$this->from.'>';
        }

    }   
    //echo $this->fromName;
    function _setHeader(){

            // boundary
            $semi_rand = md5(time());
            $this->mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

        if(!isset($this->type))
            $this->type='plain';

        if($this->type=='plain')
            $this->type='text/plain';
        else if($this->type=='html')
            $this->type='text/html';
        else if($this->type=='mixed')
            $this->type='multipart/mixed';


        if(sizeof($this->attach) || ($this->attach!=''))
           $this->type='multipart/mixed';

        if($this->type=='text/plain' || $this->type=='text/html' ){ 
            // To send HTML mail, the Content-type header must be set
            $this->headers= 'From: '.$this->_setFromName(). "\r\n".
                            'Reply-To: '.(isset($this->replyTo)?$this->replyTo:$this->from). "\r\n" .
                            'X-Mailer: PHP/' . phpversion();
            $this->headers .= 'MIME-Version: 1.0' . "\r\n";
            $this->headers .= 'Content-type: '.$this->type.'; charset=iso-8859-1' . "\r\n";
        }
        if($this->type=='multipart/mixed'){

           $this->headers=  'From: '.$this->_setFromName(). "\r\n".
                            'Reply-To: '.(isset($this->replyTo)?$this->replyTo:$this->from). "\r\n" .
                            'X-Mailer: PHP/' . phpversion();
           $this->headers.= "\nMIME-Version: 1.0\r\n" . "Content-Type: ".$this->type.";\r\n" . " boundary=\"{$this->mime_boundary}\" \r\n";

        }

        // Additional headers
        /*
        if(isset($this->to)) //* not required
        $this->headers .= 'To: '. $this->_setTo() . "\r\n";
        if(isset($this->from)) //* not required
        $this->headers .= 'From: '. $this->_setFrom() . "\r\n";
        */
        if(isset($this->cc))
        $this->headers .= 'Cc: '. $this->_setCc() . "\r\n";
        if(isset($this->bcc))
        $this->headers .= 'Bcc: '. $this->_setBcc() . "\r\n";

        //e($this->headers);

    }


    function _setMessage(){

        $this->_setHeader();
        // multipart boundary
        if($this->type=='multipart/mixed'){
            $this->_message = "\n\n" . 
            "--{$this->mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . 
            "Content-Transfer-Encoding: 7bit\n\n" . $this->message . "\n\n";
            $this->_message .= "--{$this->mime_boundary}\n";
        }
        else{
            $this->_message ="\n\n" . $this->message . "\n\n";

        }
        $this->message=$this->_message;

        if(count($this->attach)>0)
            $this->_setAttachments();


    }
    function findFileName($string)
    {
        $string=substr($string,(strrpos($string, "/")+1));
        return $string;
    }
    function _setAttachments(){

        if(is_array($this->attach)) $this->attach= implode(",",$this->attach);
        else                        $this->attach=array($this->attach);

            for($x=0;$x<count($this->attach);$x++){

                $file = fopen($this->attach[$x],"rb");
                $data = fread($file,filesize($this->attach[$x]));
                fclose($file);
                $data = chunk_split(base64_encode($data));
                $this->message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"".$this->findFileName($this->attach[$x])."\"\n" .
                "Content-Disposition: attachment;\n" . " filename=\"".$this->findFileName($this->attach[$x])."\"\n" .
                "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
                $this->message .= "--{$this->mime_boundary}\n";
            }
    }

    function sendMail(){
        //_setMessage
        $this->_setMessage();
        //e("class: ".$this->headers."<br>".$this->message."<hr>");
        $ok = @mail($this->_setTo(), $this->subject, $this->message, $this->headers);
        if ($ok) return true;
        else return false;

    }
}

// End Of class

$mail = new Mailler();
$mail->to = "example@example.com";
$mail->from = "example1@exampleServer.com";
$mail->type= "html";
$mail->subject = "test";
$mail->message = "Test mressage <h1>dgfdgfdf</h1>";
$mail->sendMail();

?>