WordPress: Send HTML emails from your plugin

December 7, 2014

By default when you use the wp_mail() function it will send out an ugly text based email. Lucky for you WordPress has an easy built in tool (surprise!) to switch the emails from text emails into html email. Simply drop the following line into your plugin and presto! Html email will flow out of it.

add_filter( 'wp_mail_content_type',create_function( '', 'return "text/html"; ' ) );

2 thoughts on “WordPress: Send HTML emails from your plugin

  1. Tanner (December 8, 2014)

    Hey Ben! Just a quick note. It’s a good idea to unhook the filter after sending the email. Otherwise any other email sent out by wp_mail will also be affected and that could get really ugly. 🙂

    1. Ben Lobaugh (blobaugh) (December 8, 2014)

      That is a great point Tanner! They sites I have used it on have been fully custom controlled so setting this for the entire site worked fine. In general use such as a publicly release plugin it is a best practice to unhook this after using it.

      You are a stud Tanner!