Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/wp mail content type


The default content type for email sent through the wp_mail function is 'text/plain' which does not allow using HTML. However, you can use the wp_mail_content_type filter to change the default content type of the email.

In general, content type is going to be 'text/plain' as the default, or 'text/html' for HTML email; but other MIME types are possible.


(string) (required) The email content type
Default: text/plain


This example will change the default content (mime) type for the wp_mail() function to 'text/html':

add_filter( 'wp_mail_content_type', 'set_content_type' );
function set_content_type( $content_type ) {
	return 'text/html';

It is not necessary to call another method if you can use anonymous functions (PHP 5.3.0+):

add_filter( 'wp_mail_content_type', function( $content_type ) {
	return 'text/html';

You could use different MIME types for different purposes by building some conditional logic into your filter:

add_filter( 'wp_mail_content_type', 'my_mail_content_type' );
function my_mail_content_type( $content_type ) {

    if ( $some_condition ) {
        return 'multipart/mixed';
    } else {
        return 'text/plain';


While there are other MIME types available, plain text and HTML are the most common.

If you are looking for a way to embed images in emails sent from via wp_mail(), such as a logo included in a signature, you need to send an HTML formatted email. You will need the wp_mail_content_type filter to set that up.

Setting the default to "text/html" can cause problems with default WordPress emails such as password reset. Line breaks will not appear and Gmail will strip out the reset link. See https://core.trac.wordpress.org/ticket/21095 for more info.

Change Log

Since: Version 2.3

Source File

wp_mail_content_type is located in wp-includes/pluggable.php