How to Send HTML Emails From WordPress Using wp_mail Function.
Yes you can use WordPress’s wp_mail() function to send HTML emails from your WordPress site. However, the default content type of wp_mail() function is set to ‘text/plain’ which does not allowed you to send HTML in emails. If you want to send HTML emails using the WordPress wp_mail() function 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. You can add this filter which is shown below.
[php] add_filter(‘wp_mail_content_type’,’set_content_type’); [/php]
Then create a function set_content_type and in that function have to return the appropriate content type, in this case it is ‘text/html’. See below
[php]
function set_content_type($content_type){
return ‘text/html’;
}
[/php]
Another Way to Set the Mail Content Type to HTML
[php]
add_filter(‘wp_mail_content_type’,create_function(”, ‘return “text/html”; ‘));
wp_mail(‘whoever@whatever.com’, ‘Email Subject’, ‘Email Message Body’);
[/php]