这个主题有什么问题?错误451 CodeIgniter电子邮件类

时间:2013-12-17 14:22:39

标签: php codeigniter qmail

所以这很奇怪。

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

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

你从哪里得到451错误?我看到451被报告为local error in processing

如果主题字符串超过76个字符,则电子邮件类会将其分解:

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 (') 

组?