malformed email subject header when subject > 75 chars using codeigniter email lib

只谈情不闲聊 提交于 2019-12-04 03:46:25

问题


I'm getting some garble in my MIME headers when the subject is over 75 chars. When the line break is encoded in the header there is an extra line break that is invalid.

Some email gateways are bouncing the email with a "Malformed MIME field: ?= =?utf-8?Q?SUBJECT?=" error.

Does anyone have any experience with utf-8 problems sending emails with CodeIgniter?


-snip-
Return-Path: ***
Subject: =?utf-8?Q?SUBJECT_LINE    <--
?=                                 <-- Problem in Subject header
 =?utf-8?Q?SUBECT_LINE_2?=         <--
To: ***
Reply-To: ***
-snip-

Update: This has nothing to do with gmail smtp. I have rewritten the question in the hope that it will help someone out in the future.


回答1:


Apparently this is a known issue, caused by Subject lines > 75 chars.

http://codeigniter.com/forums/viewthread/154493/P15/#925385

The fix was to change the email config like this:

$config['newline'] = "\r\n";
$config['crlf']    = "\n"; 



回答2:


Since I myself had this exact problem I will share the solution here since the one shared does not work with version 2.2

Find this piece of code located in system/libraries/Email.php:365

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

With this one

public function subject($subject)
{
    $subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
    $this->_set_header('Subject', $subject);
    return $this;
}


来源:https://stackoverflow.com/questions/8350865/malformed-email-subject-header-when-subject-75-chars-using-codeigniter-email-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!