0

所以这很奇怪。

我在正在生成的电子邮件中收到 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 错误吗?

4

2 回答 2

0

你从哪里得到 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 (') 

放?

于 2013-12-17T15:28:12.927 回答
0

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

$this->email->subject('A user has completed their task in '.$data['property_name']);
于 2013-12-17T14:51:09.997 回答