How to fix HTML tags showing up in emails sent with Zoho Mail
I recently ran into an issue sending HTML emails from a WordPress site using Zoho Mail. Zoho Mail provides their own plugin to easily use Zoho Mail’s API to send emails from WordPress. The plugin was just using WordPress’s built-in wp_mail function, which, by default, sends all emails with a content type of ‘text/plain’.
So in order to fix the HTML tags showing in the emails, I just needed to change the default content type for the wp_mail function. And, as expected, WordPress has a filter we can use to do so.
The code to solve the problem
Just copy and paste the following code into your functions.php file and you will be all set:
// Set the default content type for the wp_mail function
add_filter('wp_mail_content_type', 'set_wp_mail_default_content_type');
function set_wp_mail_default_content_type($content_type) {
$content_type = 'text/html';
return $content_type;
}
Or, if you are a fan of closures and short-n-sweet code, use this snippet instead:
// Set the default content type for the wp_mail function
add_filter('wp_mail_content_type', function() {
return 'text/html';
});
Need more help?
As always, just reach out if you need more help. You can reach me through my request a free estimate form.
Dustin Parker
Dustin Parker is a web developer who helps businesses build and improve their online stores with WordPress and WooCommerce. He specializes in creating custom plugins, themes, and integrations that solve real-world problems, whether that means streamlining workflows, connecting with third-party systems, or adding unique store features. Dustin's goal is always to deliver solutions that are reliable, easy to use, and built around each client's needs.