如何在CodeIgniter电子邮件中省略电子邮件主题的_prep_q_encoding

时间:2013-08-09 11:27:50

标签: php codeigniter email

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

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

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

1 个答案:

答案 0 :(得分:1)

在您的电子邮件撰写配置中: $config['wrapchars'] = 100; 以增加限制,同时写下: $config['wordwrap'] = TRUE; 来换行。希望它有所帮助。