0
votes

I've created a custom transport for CakeEmail (to allow me to use Mandrill to send email). However, whenever I access the content of the message (which is cake email template driven), it doesn't encode the characters correctly (it changes 'é' to 'é', etc). If I use CakeEmail and bypass the transport, it displays the characters correctly in the email. I've narrowed this down to $email->message('html') in the transport code. If I output $email->message('html'), the characters are already incorrect.

App::uses('AbstractTransport', 'Network/Email');
App::uses('HttpSocket', 'Network/Http');

class MandrillTransport extends AbstractTransport {
    public function send(CakeEmail $email) {
        debug($email->message('html'));exit;
    }
}

Thoughts?

1

1 Answers

0
votes

You most probably have an encoding mismatch somewhere, if for example your App.encoding doesn't match your CakeEmail::$charset, CakeEmail would try to convert the content from App.encoding to CakeEmail::$charset.

https://github.com/cakephp/.../2.6.2/lib/Cake/Network/Email/CakeEmail.php#L1338

If for example the former were iso-8859-1, and the latter utf-8, just like the content, you would end up with the result you are showing here.

// outputs é when displayed as utf-8/unicode
echo mb_convert_encoding('é', 'utf-8', 'iso-8859-1');

You'll have to do some further debugging to trace down where exactly things are going wrong.