选择语言 :

 Core_Email::_build_message

Build Final Body and attachments

void Core_Email::_build_message( )
返回值
  • void
File: ./core/classes/email.class.php
protected function _build_message()
{
    if ($this->wordwrap === true && $this->mailtype !== 'html')
    {
        $this->_body = $this->word_wrap($this->_body);
    }

    $this->_set_boundaries();
    $this->_write_headers();

    $hdr = ($this->_get_protocol() === 'mail') ? $this->newline : '';
    $body = '';

    switch ($this->_get_content_type())
    {
        case 'plain' :

            $hdr .= 'Content-Type: text/plain; charset='.$this->charset.$this->newline
                .'Content-Transfer-Encoding: '.$this->_get_encoding();

            if ($this->_get_protocol() === 'mail')
            {
                $this->_header_str .= $hdr;
                $this->_finalbody = $this->_body;
            }
            else
            {
                $this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body;
            }

            return;

        case 'html' :

            if ($this->send_multipart === false)
            {
                $hdr .= 'Content-Type: text/html; charset='.$this->charset.$this->newline
                    .'Content-Transfer-Encoding: quoted-printable';
            }
            else
            {
                $hdr .= 'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"'.$this->newline.$this->newline;

                $body .= $this->_get_mime_message().$this->newline.$this->newline
                    .'--'.$this->_alt_boundary.$this->newline

                    .'Content-Type: text/plain; charset='.$this->charset.$this->newline
                    .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
                    .$this->_get_alt_message().$this->newline.$this->newline.'--'.$this->_alt_boundary.$this->newline

                    .'Content-Type: text/html; charset='.$this->charset.$this->newline
                    .'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline;
            }

            $this->_finalbody = $body.$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline;


            if ($this->_get_protocol() === 'mail')
            {
                $this->_header_str .= $hdr;
            }
            else
            {
                $this->_finalbody = $hdr.$this->_finalbody;
            }


            if ($this->send_multipart !== false)
            {
                $this->_finalbody .= '--'.$this->_alt_boundary.'--';
            }

            return;

        case 'plain-attach' :

            $hdr .= 'Content-Type: multipart/'.$this->multipart.'; boundary="'.$this->_atc_boundary.'"'.$this->newline.$this->newline;

            if ($this->_get_protocol() === 'mail')
            {
                $this->_header_str .= $hdr;
            }

            $body .= $this->_get_mime_message().$this->newline.$this->newline
                .'--'.$this->_atc_boundary.$this->newline

                .'Content-Type: text/plain; charset='.$this->charset.$this->newline
                .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline

                .$this->_body.$this->newline.$this->newline;

        break;
        case 'html-attach' :

            $hdr .= 'Content-Type: multipart/'.$this->multipart.'; boundary="'.$this->_atc_boundary.'"'.$this->newline.$this->newline;

            if ($this->_get_protocol() === 'mail')
            {
                $this->_header_str .= $hdr;
            }

            $body .= $this->_get_mime_message().$this->newline.$this->newline
                .'--'.$this->_atc_boundary.$this->newline

                .'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"'.$this->newline.$this->newline
                .'--'.$this->_alt_boundary.$this->newline

                .'Content-Type: text/plain; charset='.$this->charset.$this->newline
                .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
                .$this->_get_alt_message().$this->newline.$this->newline.'--'.$this->_alt_boundary.$this->newline

                .'Content-Type: text/html; charset='.$this->charset.$this->newline
                .'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline

                .$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline
                .'--'.$this->_alt_boundary.'--'.$this->newline.$this->newline;

        break;
    }

    $attachment = array();
    for ($i = 0, $c = count($this->_attach_name), $z = 0; $i < $c; $i++)
    {
        $filename = $this->_attach_name[$i][0];
        $basename = is_null($this->_attach_name[$i][1]) ? basename($filename) : $this->_attach_name[$i][1];
        $ctype = $this->_attach_type[$i];
        $file_content = '';

        if ($this->_attach_type[$i] === '')
        {
            if ( ! file_exists($filename))
            {
                $this->_set_error_message('lang:email_attachment_missing', $filename);
                return false;
            }

            $file = filesize($filename) +1;

            if ( ! $fp = fopen($filename, FOPEN_READ))
            {
                $this->_set_error_message('lang:email_attachment_unreadable', $filename);
                return false;
            }

            $ctype = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
            $file_content = fread($fp, $file);
            fclose($fp);
        }
        else
        {
            $file_content =& $this->_attach_content[$i];
        }

        $attachment[$z++] = '--'.$this->_atc_boundary.$this->newline
            .'Content-type: '.$ctype.'; '
            .'name="'.$basename.'"'.$this->newline
            .'Content-Disposition: '.$this->_attach_disp[$i].';'.$this->newline
            .'Content-Transfer-Encoding: base64'.$this->newline;

        $attachment[$z++] = chunk_split(base64_encode($file_content));
    }

    $body .= implode($this->newline, $attachment).$this->newline.'--'.$this->_atc_boundary.'--';
    $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr.$body;
    return;
}