Magento issue with email charset

Magento issue with email charset

August 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento issue with email charset

Solving UTF-8 Charset Issues in Magento Email Sending

Email communication is a critical component of any e-commerce platform like Magento. However, ensuring that special characters are properly encoded within the email body can be challenging. This post addresses a common issue faced by developers when sending emails with UTF-8 charset using the built-in Magento core/email model.

The Original Email Sending Function

The original code provided in the question uses the Mage::getModel('core/email') to send an email:

$mail = Mage::getModel('core/email');
$mail->setToName($name);
$mail->setToEmail($email);
$mail->setBody($content);
$mail->setSubject($subject);
$mail->setFromEmail('test@test.com');
$mail->setFromName("Test");
$mail->setType('html');

try {
    $mail->send();
    Mage::getSingleton('customer/session')->setData('success',Mage::helper('adminhtml')->__('Your request has been sent'));
}
catch (Exception $e) {
    Mage::getSingleton('customer/session')->setData('error',Mage::helper('adminhtml')->__('Unable to send email.'));
}

While this code works for basic text, it does not explicitly set the character encoding of the email body. This can lead to special characters being misinterpreted or displayed incorrectly in the recipient’s mail client.

The Solution: Using Zend_Mail

To ensure proper UTF-8 encoding, we can use the Zend_Mail class instead of the Magento core/email model:

public function sendZendMail($name,$email,$subject,$content){
    $mail = new Zend_Mail('UTF-8');
    $mail->setBodyHtml($content);
    $mail->setFrom('your@frommail.com');
    $mail->addTo($email, 'No reply');
    $mail->setSubject($subject);

    try {
        $mail->send();
        Mage::getSingleton('core/session')->addSuccess('Mail was successfully send.');
    }
    catch(Exception $ex) {
        Mage::getSingleton('core/session')->addError('Unable to send email.');
    }
}

This function explicitly sets the character encoding of the mail object to UTF-8. The setBodyHtml() method is used with the content variable, which ensures that any HTML entities are properly rendered in the recipient’s mail client.

Why This Solution Works

The Zend Mail library is a powerful component provided by Magento. It offers more fine-grained control over email sending compared to the built-in core/email model. By explicitly setting the character encoding to UTF-8 and using the setBodyHtml() method, we ensure that special characters are properly encoded and displayed in the recipient’s mail client.

Best Practices for Email Sending in Magento

While this solution provides a direct fix for the charset issue, it’s important to note some best practices:

  1. Always use a consistent naming convention for your custom functions.
  2. Consider using a helper class for email-related functionality if you have multiple modules sending emails.
  3. Test your email templates thoroughly across different mail clients and devices.
  4. Monitor your email queue regularly to ensure no failed or pending emails.

Conclusion

In conclusion, ensuring proper UTF-8 encoding in Magento email sending requires a nuanced understanding of the available tools. By leveraging the Zend Mail library and explicitly setting the character encoding, we can prevent special characters from being misinterpreted in the recipient’s mail client.

Remember to always test your email templates thoroughly and monitor your email queue for any potential issues. For more advanced solutions and tips on Magento development, feel free to explore our resources at Laravel Company.

Admin Email Customers Errors

Our network