I think, therefore I am. I am, therefore I sail

WordPress: Send HTML emails from your plugin

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"; ' ) );

Previous

Ghost leak in the water system annihilated

Next

WebDevStudios is helping kids in Uganda have a brighter future

2 Comments

  1. 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. 🙂

    • 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!

Powered by WordPress & Beards