什么';这个主题行错了吗?错误451 CodeIgniter电子邮件类


What's wrong with this subject line? Error 451 CodeIgniter Email class

所以这很奇怪。

我在生成的一封电子邮件中收到了一个451错误,只是导致它的原因是主题行的纯文本部分:s

此主题行通过精细:

$this->email->subject('New task in "'.$data['property_name'].'"');

这会导致451错误:

$this->email->subject('A user has completed their task in "'.$data['property_name'].'"');

作为参考,错误451适用于裸LF(http://cr.yp.to/docs/smtplf.html)。这通常是由于没有在设置中声明行结束规则,或者使用单引号,即"/r/n/"而不是"/r/n"。我的设置是正确的,电子邮件工作正常。

调试器中值得注意的是,较长的行显示为:

Subject: =?utf-8?Q?A_user_has_completed_their_task_in_"TASKNAME
?=
 =?utf-8?Q?"?=

而正在工作的似乎是:

Subject: =?utf-8?Q?New_task_in_"TASKNAME"?=

这是CI错误吗?

我认为您混淆了单引号和双引号。尝试:

$this->email->subject('A user has completed their task in '.$data['property_name']);

451错误是从哪里得到的?我看到451被报告为处理中的本地错误。

如果主题字符串超过76个字符,则Email类会对其进行分解:

109 // Line length must not exceed 76 characters, so we adjust for
110 // a space, 7 extra characters =??Q??=, and the charset that we will add to each line

你可以看到它在行动:

function test()
{
    echo "<pre>";
    print_r($this->_prep_q_encoding('A user had completed their task in "Going to change string to something"'));
}

function _prep_q_encoding($str, $from = FALSE)
{
    $this->crlf= "'n";  
    $this->charset = 'utf-8';
    $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;
}

哪个输出

=?utf-8?Q?A_user_had_completed_their_task_in_"Going_to_change_string_to_?=
 =?utf-8?Q?something"?=

我看到其他人在设置电子邮件配置的方式上有问题。你有吗

$config['crlf'] = "'r'n"; //double quotes ("), not single (') 
$config['newline'] = "'r'n";  //double quotes ("), not single (') 

设置?