4

我的电子邮件有问题,html 没问题,但是当我打开它们时,文本和链接中有错误,其中一些字符更改为 = like

Thanks for joining . your log=n details are here ma=e sure you keep them safe.
To verify your email address, please follow this link:

 Finish your registration...

Link doesn't work? Copy the following link to your browser address bar:  http://www.myurl.com/dev=l/panel/auth/activate/123131/123131

Please verify your email within 123131 hours, otherwise your registration =ill become invalid and you will have to register again.

每个图像和链接甚至文本都被破坏了我在想它与{unwrap}有关但没有帮助

这是 config/email.php

$config['email_notification']['protocol'] = 'smtp';
$config['email_notification']['smtp_host'] = 'smtp.live.com';
$config['email_notification']['smtp_user'] = 'xxxxx';
$config['email_notification']['smtp_pass'] = 'xxxxxxx';
$config['email_notification']['smtp_port'] = '587';
$config['email_notification']['mailtype'] = 'html';
$config['email_notification']['charset'] = 'utf-8';
$config['email_notification']['wordwrap'] = false;
$config['email_notification']['smtp_crypto'] = 'tls';

这是控制器

 $this->load->library('email');



    $this->email->initialize($this->config->item('email_notification'));
    $this->email->subject('Email Test');

    $this->email->set_newline("\r\n");
    $this->email->from('xxxxxx'); // change it to yours
    $this->email->to('xxxxx');
    $this->email->subject('Email Test');

    $data=array(
        'site_name'=>'tralalalal',
        'user_id'=>'123131',
        'new_email_key'=>'123131',
        'activation_period'=>'123131',
        'email'=>'123131',
        'title'=>'123131',

    );
    $this->email->message($this->load->view('email/activate_account/en',$data,true));

电子邮件正文是

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
    /* Client-specific Styles */
#outlook a{padding:0;} /* Force Outlook to provide a "view in browser" button. */
body{width:100% !important;} .ReadMsgBody{width:100%;} .ExternalClass{width:100%;} /* Force Hotmail to display emails at full width */
body{-webkit-text-size-adjust:none;} /* Prevent Webkit platforms from changing default text sizes. */

    /* Reset Styles */
body{margin:0; padding:0;}
img{border:0; height:auto; line-height:100%; outline:none; text-decoration:none;}
table td{border-collapse:collapse;}
#backgroundTable{height:100% !important; margin:0; padding:0; width:100% !important;}
</style>
</head>
<body>

谢谢

4

3 回答 3

2

我找到了答案,所以如果有人有同样的问题

这就是为什么


该标准对一行中的字符数有两个限制。每行字符必须不超过
998 个字符,并且应该不超过 78 个字符,不包括
CRLF。

998 个字符的限制是由于在发送、接收或存储 Internet 消息格式消息的许多实现中的限制,这些消息根本无法在一行中处理超过 998 个字符。为了健壮性,接收实现可以很好地处理一行中任意大量的字符。然而,有很多实现(符合 [RFC2821] 的传输要求)不接受包含超过 1000 个字符的消息,包括每行的 CR 和 LF,因此不创建此类消息对实现很重要。

更保守的 78 个字符推荐是为了适应显示这些
消息的用户界面的许多实现,这些消息可能会截断或灾难性地换
行,每行超过 78 个字符的显示,尽管这样的
实现不符合本
规范的意图(以及 [RFC2821] 的意图,如果它们实际上导致
信息丢失)。同样,即使对消息施加了这种限制,它也依赖于显示消息的实现

这是您更改代码以覆盖此限制的地方 system/libraries/email.php

原版

protected function _prep_quoted_printable($str, $charlim = '')
{
    // Set the character limit
    // Don't allow over 76, as that will make servers and MUAs barf
    // all over quoted-printable data
    if ($charlim == '' OR $charlim > '76')
    {
        $charlim = '76';
    }

快速解决 :)

protected function _prep_quoted_printable($str, $charlim = '')
{
    // Set the character limit
    // Don't allow over 76, as that will make servers and MUAs barf
    // all over quoted-printable data
    if ($charlim == '' OR $charlim > '76')
    {
        $charlim = '200';
    }
于 2013-02-17T01:13:06.053 回答
0

我认为问题出在 _prep_quoted_printable 函数中。幸运的是,从 v5.3 开始,这个函数有一个原生 PHP 版本

通过将电子邮件类中的 _prep_quoted_printable 实例替换为 PHP 本机函数quoted_printable_encode,我能够解决类似的问题。

这相当于我的 _build_message() 看起来像这样:

    /**
 * Build Final Body and attachments
 *
 * @access  protected
 * @return  void
 */
protected function _build_message()
{
    if ($this->wordwrap === TRUE  AND  $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;
            $hdr .= "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;

        break;
        case 'html' :

            if ($this->send_multipart === FALSE)
            {
                $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
                $hdr .= "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;
                $body .= "--" . $this->_alt_boundary . $this->newline;

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

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

            // $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline;
            $this->_finalbody = $body . quoted_printable_encode($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;

        break;
        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;
            $body .= "--" . $this->_atc_boundary . $this->newline;

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

            $body .= $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;
            $body .= "--" . $this->_atc_boundary . $this->newline;

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

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

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

            // $body .= $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline;
            $body .= quoted_printable_encode($this->_body) . $this->newline . $this->newline;
            $body .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline;

        break;
    }

    $attachment = array();

    $z = 0;

    for ($i=0; $i < count($this->_attach_name); $i++)
    {
        $filename = $this->_attach_name[$i];
        $basename = basename($filename);
        $ctype = $this->_attach_type[$i];

        if ( ! file_exists($filename))
        {
            $this->_set_error_message('lang:email_attachment_missing', $filename);
            return FALSE;
        }

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

        $attachment[$z++] = $h;
        $file = filesize($filename) +1;

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

        $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file)));
        fclose($fp);
    }

    $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";


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

    return;
}
于 2016-07-01T09:30:28.380 回答
0

有一个封闭的 Outlook 环境,不希望发送到另一个邮件客户端。

结果相似,但codeigniter版本不同。我有一个 wrapchars 变量来允许它改变。问题是它在 _prep_quoted_printable 中使用了硬编码的 76。我把76改成

    $this->wrapchars 

世界上的一切都变得美好。

于 2020-08-02T23:46:47.357 回答