0
votes

I'm using the Mandrill Transport (https://github.com/khanlou/MandrillTransport-CakePHP) to send mails in my cakephp application.

But when sending mails I get ?? in odd places in my subject line due to special characters.

Subject = 'Découvrez vite toutes les nouveautés sur r7site.com'

Result = 'Découvrez vite toutes les nouveautés sur r7?? site.com'

As you can see the ?? are placed very strangely.

When I'm using the default cakephp mail it works like a charm...

public $default = array(
    'transport' => 'Mail',
    'from' => '[email protected]',
    'charset' => 'utf-8',
    'headerCharset' => 'utf-8',
);

I guess it has something to do with the utf-8 charset, but I'm not sure. The content works fine with mandrill and actually the chars are printed fine as well in the subject. Just the ?? should not be there...

2

2 Answers

1
votes

I finally found the solution. Apparently CakePHP adds new line characters to the title causing the title to break. Although it only occurred with special characters.

debug of the title:

'=?UTF-8?B?RMOpY291dnJleiB2aXRlIHRvdXRlcyBsZXMgbm91dmVhdXTDqXMgc3VyIHE4?= =?UTF-8?B?bWF6b3V0LmJl?='

solution in the MandrillTestTransport

$subject = str_replace(array(PHP_EOL, "\r"), '', $this->_cakeEmail->subject());

$message = array(
    'html' => $this->_cakeEmail->message('html'),
    'text' => $this->_cakeEmail->message('text'),
    'subject' => $subject,
    ...
);
0
votes

You need to convert your content from ASCII to UTF-8, and for this you can use below function for this because special characters is many time not supported by some of the third party apis like mandrill.

mb_convert_encoding($subject, 'UTF-8', 'ASCII');