Magento – custom transactional email special characters issue

character encodingtransactional-mail

I have an issue with transactional emails with special characters (é, è, à, etc.)

For the "Official Emails" such as "order_new.html" which are sent by magento core, everything works fine and all the special characters are well displayed in the mailbox.

But for custom transactional emails I define in Backend and send using custom modules special characters are not displayed correctly

ex : été vérifiés avec succès

I tried defining utf-8 encoding both in email template and in the module code with setHeader(), but I have the same result.

Here is my code :

$mail = Mage::getModel('core/email')
        ->setToName($ToName)
        ->setToEmail($ToEmail)
        ->setHeader('Content-type', 'text/xml; charset=UTF-8')
        ->setBody($processedTemplate)
        ->setSubject('tototototo')
        ->setFromEmail($senderEmail)
        ->setFromName($senderName)
        ->setType('html');   

Best Answer

I managed to find a solution by using Zend Mail :

$mail = new Zend_Mail('UTF-8');
$mail->setType(Zend_Mime::MULTIPART_RELATED);
$mail->setBodyHtml($processedTemplate);
$mail->setFrom($senderEmail, $senderName);
$mail->addTo($ToEmail, $ToName);
$mail->setSubject('I love UTF8');

If it can help...