CodeIgniter Forums

Full Version: SMTP library - _prep_q_encoding() function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I am using Codeigniter SMTP email library to send emails, with following config values:

$config = array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://',
    'smtp_user' => 'SMTP USERNAME',
    'smtp_pass' => 'SMTP PASSWORD',
    'smtp_port' => 465,
    'mailtype' => 'html',
    'newline' => "\r\n",
    'crlf' => "\r\n"

Everything works fine, till I use an email subject which is more than 62 characters in length.

The _prep_q_encoding() function performs "Q Encoding" on the subject. This function divides the subject into different lines ensuring that none of the lines exceed 76 characters including the 7 extra characters "=??Q??=" and the charset. At the end of each line, the crlf [which is "\r\n"] is appended and then each line is wrapped by the extra characters.

$str = trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));

The above statement creates a problem as '?=' is added after '\r' [from crlf] of each line, resulting in transaction failed due to illegal header.

Can someone please explain me, what exactly is happening and how can I solve the problem?