0

我在 Outlook 正确显示电子邮件内容和附件时遇到问题,电子邮件内容在 Google Mail 或 Hotmail 等邮件服务提供商上运行良好。

这是 Outlook 产生的电子邮件内容:

X-Mailer: simpleEmailClass v1.0

MIME-Version: 1.0

Content-Type: multipart/mixed; boundary="13406541204fe8c2284f5aa"

Message-Id: < - removed - >
Date: Mon, 25 Jun 2012 20:55:20 +0100 (BST)

--13406541204fe8c2284f5aa

Content-Type: multipart/alternative; boundary="13406541204fe8c2284f98f"


--13406541204fe8c2284f98f

Content-Type: text/plain; charset="ISO-8859-1"

Content-Transfer-Encoding: quoted-printable

Dear Rachel
Further to your recent enquiry please accept this email as confirmation of your booking.
Kind Regards
Hanna

--13406541204fe8c2284f98f

Content-Type: text/html; charset="ISO-8859-1"

Content-Transfer-Encoding: quoted-printable



<html>
<body>
<html><body><p>

    <span style="font-family: arial, helvetica, sans-serif; font-size: 12px; ">Dear Rachel</span></p>

<p>

    <span style="font-size:12px;"><span style="font-family:arial,helvetica,sans-serif;">Further to your recent enquiry please accept this email as confirmation of your booking.</span></span></p>

<p>

    <span style="font-size:12px;"><span style="font-family:arial,helvetica,sans-serif;">Kind Regards</span></span></p>

<p>

    <font face="arial, helvetica, sans-serif">Hanna</font></p>

</body></html>
</body>
</html>


--13406541204fe8c2284f98f--



--13406541204fe8c2284f5aa

Content-Type: application/pdf; name="invoice.pdf"

Content-Transfer-Encoding: base64

Content-Disposition: attachment; filename="invoice.pdf"

JVBERi0xLjMKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZwovT3V0bGluZXMgMiAwIFIKL1Bh

^^ This go on and on for a long time, thought it was best not to post it all.

--13406541204fe8c2284f5aa--

上面的这封电子邮件是在 Outlook 中看到的,在 Google Mail 中,它显示为 HTML 版本。

这是我用于电子邮件类的代码。

<?php
class sec {
    var $secVersion = '1.0';
    var $to = '';
    var $Cc = array ();
    var $Bcc = array ();
    var $subject = '';
    var $message = '';
    var $attachment = array ();
    var $embed = array ();
    var $charset = 'ISO-8859-1';
    var $emailboundary = '';
    var $emailheader = '';
    var $textheader = '';
    var $errors = array ();

    function __construct($toname, $toemail, $fromname, $fromemail) {
        $this->emailboundary = uniqid ( time () );
        $this->to = "{$toname} <" . $this->validateEmail ( $toemail ) . ">";
        $email = $this->validateEmail ( $fromemail );
        $this->emailheader .= "From: {$fromname} <{$email}>\r\n";
    }

    function validateEmail($email) {
        if (! preg_match ( '/^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\\.)+[A-Z]{2,4}$/i', $email ))
            die ( 'The Email ' . $email . ' is not Valid.' );

        return $email;
    }

    function Cc($email) {
        $this->Cc [] = $this->validateEmail ( $email );
    }

    function Bcc($email) {
        $this->Bcc [] = $this->validateEmail ( $email );
    }

    function buildHead($type) {
        $count = count ( $this->$type );
        if ($count > 0) {
            $this->emailheader .= "{$type}: ";
            $array = $this->$type;
            for($i = 0; $i < $count; $i ++) {
                if ($i > 0)
                    $this->emailheader .= ',';
                $this->emailheader .= $this->validateEmail ( $array [$i] );
            }
            $this->emailheader .= "\r\n";
        }
    }

    function buildMimeHead() {
        $this->buildHead ( 'Cc' );
        $this->buildHead ( 'Bcc' );

        $this->emailheader .= "X-Mailer: simpleEmailClass v{$this->secVersion}\r\n";
        $this->emailheader .= "MIME-Version: 1.0\r\n";
    }

    function buildMessage($subject, $message = '') {
        $textboundary = uniqid ( time () );
        $this->subject = strip_tags ( trim ( $subject ) );

        $this->textheader = "Content-Type: multipart/alternative; boundary=\"$textboundary\"\r\n\r\n";
        $this->textheader .= "--{$textboundary}\r\n";
        $this->textheader .= "Content-Type: text/plain; charset=\"{$this->charset}\"\r\n";
        $this->textheader .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
        $this->textheader .= strip_tags ( $message ) . "\r\n\r\n";
        $this->textheader .= "--$textboundary\r\n";
        $this->textheader .= "Content-Type: text/html; charset=\"$this->charset\"\r\n";
        $this->textheader .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
        $this->textheader .= "<html>\n<body>\n{$message}\n</body>\n</html>\r\n\r\n";
        $this->textheader .= "--{$textboundary}--\r\n\r\n";
    }

    function mime_type($file) {
        return (function_exists ( 'mime_content_type' )) ? mime_content_type ( $file ) : trim ( exec ( 'file -bi ' . escapeshellarg ( $file ) ) );
    }

    function attachment($file, $filename = NULL, $direct_input = FALSE, $mime = '') {
        if(!$direct_input)
        {
            if (is_file ( $file )) {
                $basename = $filename? $filename: basename ( $file );
                $attachmentheader = "--{$this->emailboundary}\r\n";
                $attachmentheader .= "Content-Type: " . $this->mime_type ( $file ) . "; name=\"{$basename}\"\r\n";
                $attachmentheader .= "Content-Transfer-Encoding: base64\r\n";
                $attachmentheader .= "Content-Disposition: attachment; filename=\"{$basename}\"\r\n\r\n";
                $attachmentheader .= chunk_split ( base64_encode ( fread ( fopen ( $file, "rb" ), filesize ( $file ) ) ), 72 ) . "\r\n";

                $this->attachment [] = $attachmentheader;
            } else {
                die ( 'The File ' . $file . ' does not exsist.' );
            }
        }
        else
        {
            $basename = $filename;
            $attachmentheader = "--{$this->emailboundary}\r\n";
            $attachmentheader .= "Content-Type: $mime; name=\"{$basename}\"\r\n";
            $attachmentheader .= "Content-Transfer-Encoding: base64\r\n";
            $attachmentheader .= "Content-Disposition: attachment; filename=\"{$basename}\"\r\n\r\n";
            $attachmentheader .= chunk_split ( base64_encode ( $file ), 72 ) . "\r\n";

            $this->attachment [] = $attachmentheader;
        }
    }

    function embed($file) {
        if (is_file ( $file )) {
            $basename = basename ( $file );
            $fileinfo = pathinfo ( $basename );
            $contentid = md5 ( uniqid ( time () ) ) . "." . $fileinfo ['extension'];
            $embedheader = "--{$this->emailboundary}\r\n";
            $embedheader .= "Content-Type: " . $this->mime_type ( $file ) . "; name=\"{$basename}\"\r\n";
            $embedheader .= "Content-Transfer-Encoding: base64\r\n";
            $embedheader .= "Content-Disposition: inline; filename=\"{$basename}\"\r\n";
            $embedheader .= "Content-ID: <{$contentid}>\r\n\r\n";
            $embedheader .= chunk_split ( base64_encode ( fread ( fopen ( $file, "rb" ), filesize ( $file ) ) ), 72 ) . "\r\n";

            $this->embed [] = $embedheader;

            return "<img src=3D\"cid:{$contentid}\">";
        } else {
            die ( 'The File ' . $file . ' does not exsist.' );
        }
    }

    function sendmail() {
        $this->buildMimeHead ();

        $header = $this->emailheader;

        $attachcount = count ( $this->attachment );
        $embedcount = count ( $this->embed );

        if ($attachcount > 0 || $embedcount > 0) {
            $header .= "Content-Type: multipart/mixed; boundary=\"{$this->emailboundary}\"\r\n\r\n";
            $header .= "--{$this->emailboundary}\r\n";
            $header .= $this->textheader;

            if ($attachcount > 0)
                $header .= implode ( "", $this->attachment );
            if ($embedcount > 0)
                $header .= implode ( "", $this->embed );
            $header .= "--{$this->emailboundary}--\r\n\r\n";
        } else {
            $header .= $this->textheader;
        }

        return mail ( $this->to, $this->subject, $this->message, $header );
    }
}

我该怎么做才能使 Outlook 中的电子邮件仅显示纯文本或 html 和附件,而不是当前显示的方式。

谢谢

4

2 回答 2

1

我不能确定,但​​我似乎记得遇到过同样的问题,结果发现使用 '\n' 而不是 '\r\n' 有帮助,你试过吗?

于 2012-06-25T20:17:02.843 回答
0

我最近在向较新的电子邮件客户端发送电子邮件时遇到了类似的问题。我使用的是 Thunderbird 3,升级到 v8 或当时的任何版本(肯定是更新的)后,所有的电子邮件都没有附件和一些电子邮件的源代码。

修复更改为单个多部分/混合容器。在示例中,您有 2 个容器。对我来说看起来不错,但删除嵌套容器解决了这个问题。

另外,我使用 \n 而不是 \r\n

于 2012-07-10T23:16:50.470 回答