How to Change WordPress Email Content Type to HTML Instead of Text

[ad_1]

WordPress uses wp_mail function to send all emails and the default content type for these emails is text/plain. It simply means that all emails, goes through WordPress, will be sent in text format only and WordPress will not allow any HTML to be placed in your emails. But on a project, you may require to send emails in HTML format and for that you must change WordPress email content type, to allow you to have HTML in them. Unfortunately WordPress does not have any built in option to change email content types. But luckily, there is a easy way to change WordPress email content type to text/html from default text/plain.

To change WordPress email content type, we will use wp_mail_content_type filter. With the help of this filter, we will set the email content type to HTML allowing us to style our emails in anyway we want. This will also allow us to brand our emails with our company logo and insert images in email.

You can dump this code snippet in your functions.php file. It will automatically change WordPress email content type to HTML. Now start sending HTML emails. 🙂

// change WordPress email content type to HTML
function wpcs_set_email_content_type() {
    return 'text/html';
}
add_filter( 'wp_mail_content_type', 'wpcs_set_email_content_type' );
[ad_2]

Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads