0

我今天遇到了一个奇怪的问题。我在发送电子邮件时使用 Codeigniter 框架。有时,如果电子邮件主题很长,单词就会中断。例如,我的主题是:

This is a notification form test 

但在发送的邮件中显示如下:

This is a notification form t est

如您所见test,现在是t est. 我搜索并找到了这个功能:

private function _prep_q_encoding($str, $from = FALSE)
    {
        $str = str_replace(array("\r", "\n"), array('', ''), $str);

        // Line length must not exceed 76 characters, so we adjust for
        // a space, 7 extra characters =??Q??=, and the charset that we will add to each line
        $limit = 75 - 7 - strlen($this->charset);

        // these special characters must be converted too
        $convert = array('_', '=', '?');

        if ($from === TRUE)
        {
            $convert[] = ',';
            $convert[] = ';';
        }

        $output = '';
        $temp = '';

        for ($i = 0, $length = strlen($str); $i < $length; $i++)
        {
            // Grab the next character
            $char = substr($str, $i, 1);
            $ascii = ord($char);

            // convert ALL non-printable ASCII characters and our specials
            if ($ascii < 32 OR $ascii > 126 OR in_array($char, $convert))
            {
                $char = '='.dechex($ascii);
            }

            // handle regular spaces a bit more compactly than =20
            if ($ascii == 32)
            {
                $char = '_';
            }

            // If we're at the character limit, add the line to the output,
            // reset our temp variable, and keep on chuggin'
            if ((strlen($temp) + strlen($char)) >= $limit)
            {
                $output .= $temp.$this->crlf;
                $temp = '';
            }

            // Add the character to our temporary line
            $temp .= $char;
        }

        $str = $output.$temp;

        // wrap each line with the shebang, charset, and transfer encoding
        // the preceding space on successive lines is required for header "folding"
        $str = trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));

        return $str;
    }

来自

public function subject($subject)
{
    $subject = $this->_prep_q_encoding($subject);
    $this->_set_header('Subject', $subject);
    return $this;
}

在第一个函数中它说:

// Line length must not exceed 76 characters

所以这就是问题所在。如何在不编辑基本功能的情况下为电子邮件添加更长的主题?在不破坏单词的情况下支持较长主题的最佳方法是什么?请帮助,提前谢谢。

4

1 回答 1

1

在您的电子邮件配置中写入 :$config['wrapchars'] = 100;以增加限制,还要写入 :$config['wordwrap'] = TRUE;来换行。希望能帮助到你。

于 2013-08-09T11:38:40.260 回答