Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Change WordPress Email Content Types To HTML

DZone's Guide to

Change WordPress Email Content Types To HTML

· Web Dev Zone ·
Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

All emails in WordPress are sent using the function wp_mail, the default content type for these email are in text/plain, which does not allow HTML to be placed in your emails.

If you want to create custom HTML emails you need to change the content type of the emails to allow you to have HTML in them.

To change the content type of WordPress email you can use the filter wp_mail_content_type.

add_filter( 'wp_mail_content_type', 'set_html_content_type' );
/**
 * Set the HTML content type
 */
function set_html_content_type()
{
    return 'text/html';
}

All you will have to do is return from the filter the string text/html which will set the content type to HTMLs allowing you to style emails in anyway you want. Allowing you to brand your emails with your website logo or include other images like post feature images in the email.

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}