Title: wp_mail_content_type
Published: April 25, 2014
Last modified: February 24, 2026

---

# apply_filters( ‘wp_mail_content_type’, string $content_type )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#wp--skip-link--target)

Filters the [wp_mail()](https://developer.wordpress.org/reference/functions/wp_mail/)
content type.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#parameters)󠁿

 `$content_type`string

Default [wp_mail()](https://developer.wordpress.org/reference/functions/wp_mail/)
content type.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#more-information)󠁿

 * The default content type for email sent through the [wp_mail()](https://developer.wordpress.org/reference/functions/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.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#source)󠁿

    ```php
    $content_type = apply_filters( 'wp_mail_content_type', $content_type );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/pluggable.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/pluggable.php#L519)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/pluggable.php#L519-L519)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_staticize_emoji_for_email()](https://developer.wordpress.org/reference/functions/wp_staticize_emoji_for_email/)`wp-includes/formatting.php` |

Converts emoji in emails into static images.

  | 
| [wp_mail()](https://developer.wordpress.org/reference/functions/wp_mail/)`wp-includes/pluggable.php` |

Sends an email, similar to PHP’s mail function.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.3.0](https://developer.wordpress.org/reference/since/2.3.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#comment-content-777)
 2.    [Helen Hou-Sandi](https://profiles.wordpress.org/helen/)  [  11 years ago  ](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/#comment-777)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%23comment-777)
     Vote results for this note: 11[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%23comment-777)
 4.  **Switch to HTML formatted email when using `[wp_mail()](https://developer.wordpress.org/reference/functions/wp_mail/)`:**
 5.      ```php
         /**
          * Filter the mail content type.
          */
         function wpdocs_set_html_mail_content_type() {
         	return 'text/html';
         }
         add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
     
         $to      = 'sendto@example.com';
         $subject = 'The subject';
         $body    = 'The email body content';
     
         wp_mail( $to, $subject, $body );
     
         // Reset content-type to avoid conflicts -- https://core.trac.wordpress.org/ticket/23578
         remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%3Freplytocom%3D777%23feedback-editor-777)
 7.   [Skip to note 6 content](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#comment-content-5648)
 8.    [UrlDev](https://profiles.wordpress.org/urldev/)  [  4 years ago  ](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/#comment-5648)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%23comment-5648)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%23comment-5648)
 10. Follow the bellow code snippet to set `wp_mail();` content type without using `
     add_filter( 'wp_mail_content_type', 'your_function_name' );`.
 11. To send HTML formatted mail, you can specify the Content-Type HTTP header in the`
     $headers` parameter:
 12.     ```php
         $to = 'sendto@example.com';
         $subject = 'The subject';
         $body = 'The email body content';
         $headers = array( 'Content-Type: text/html; charset=UTF-8' );
     
         wp_mail( $to, $subject, $body, $headers );
         ```
     
 13. That’s all about it. Thank you!
 14.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%3Freplytocom%3D5648%23feedback-editor-5648)
 15.  [Skip to note 7 content](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#comment-content-4740)
 16.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/#comment-4740)
 17. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%23comment-4740)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%23comment-4740)
 18. Examples migrated from Codex:
 19. The following example will change the default content (mime) type for the `wp_mail()`
     function to ‘text/html’:
 20.     ```php
         add_filter( 'wp_mail_content_type', 'set_content_type' );
     
         function set_content_type( $content_type ) {
         	return 'text/html';
         }
         ```
     
 21. The following example shows that it is not necessary to call another method if
     you can use anonymous functions (PHP 5.3.0+):
 22.     ```php
         add_filter( 'wp_mail_content_type', function( $content_type ) {
         	return 'text/html';
         } );
         ```
     
 23. The following example shows that you could use different MIME types for different
     purposes by building some conditional logic into your filter:
 24.     ```php
         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';
             }
         }
         ```
     
 25.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%3Freplytocom%3D4740%23feedback-editor-4740)
 26.  [Skip to note 8 content](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/?output_format=md#comment-content-4741)
 27.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/wp_mail_content_type/#comment-4741)
 28. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%23comment-4741)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%23comment-4741)
 29. Example migrated from Codex:
 30. If you change the content type to `text/html`, it will cause problems with password
     reset emails.
 31. To remedy this, consider:
      modifying the email body of password reset emails to
     make it work with ‘`text/html`‘ content type OR reset the content type back to‘`
     text/plain`‘ after you’re done sending the custom emails ( either by explicitly
     resetting the content type back to ‘`text/plain`‘ or by removing the callback 
     function filter that changes the content type to ‘`text/html`‘ with `remove_filter()`)
 32. The following example shows how to use the filter ``retrieve_password_message``
     to make the email body of password reset emails work with ‘`text/html`‘ content
     type:
 33.     ```php
         // adding support for html emails
         add_filter( 'wp_mail_content_type','mycustom_set_content_type' );
     
         function mycustom_set_content_type() {
                 return "text/html";
         }
     
         // also filter the password reset email for compatibility with the HTML format
         add_filter( 'retrieve_password_message', 'mycustom_retrieve_password_message', 10, 1 );
     
         function mycustom_retrieve_password_message( $message ) {
                 $message = str_replace('<','',$message);
                 $message = str_replace('>','',$message);
                 $message = str_replace("\n",'<br>',$message);
                 return $message;
         }
         ```
     
 34. The following example shows how to reset the content type back to ‘`text/plain`‘
     by removing the callback function filter that changes the content type to ‘`text/
     html`‘ with `remove_filter()` :
 35.     ```php
         add_filter( 'wp_mail_content_type', 'set_content_type' );
     
         function set_content_type( $content_type ) {
             return 'text/html';
         }
     
         remove_filter( 'wp_mail_content_type', 'set_content_type' );
         ```
     
 36.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F%3Freplytocom%3D4741%23feedback-editor-4741)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_content_type%2F)
before being able to contribute a note or feedback.