How to Send HTML Emails From WordPress Using wp_mail Function

Posted by admin 22 May 2011

You can use WordPress’s wp_mail() function to send emails from your WordPress site. However, the default content type is ‘text/plain’ which does not allow using HTML. If you want to send HTML emails then you will need to set the content type of the email to “text/html” by using the ‘wp_mail_content_type’ filter.This is how you can do that:

before you send your wp_mail call add a filter to wp_mail_content_type

add_filter('wp_mail_content_type','set_content_type');

Then in your set_content_type function have it return the appropriate content type, in this case ‘text/html’

function set_content_type($content_type){
return 'text/html';
}

A More Compressed Way to Set the Mail Content Type to HTML

add_filter('wp_mail_content_type',create_function('', 'return "text/html"; '));
wp_mail('whoever@whatever.com', 'Subject', 'Message');

Related posts:

  1. HTML to WordPress: Header.php
  2. Part 1: HTML to WordPress
No tags for this post.

2 Comments »

  • Tahir Yasin said:

    Information was helpful, can you tell me how to receive all parameters of the WP_MAIL ( $to, $from, $subject,$message)in a hook or filter?

Leave your response!

You can subscribe to these comments via RSS.