Are your WordPress-sent emails looking a little… drab? By default, WordPress sends emails in plain text, which means no formatting, no nice colors, and definitely no images. If you want your welcome emails, password resets, or contact form notifications to look professional and engaging, you need to switch the mail type to HTML.
Here’s a quick guide on why and how you can make that essential change.
🤔 Why Use HTML for WordPress Emails?
The primary reason is presentation and user experience. Plain text emails are reliable, but they’re not visually appealing. Switching to HTML allows you to:
- Format Text: Use bold, italics, headings, and lists.
- Include Images and Logos: Crucial for branding and professional appearance.
- Utilize Colors and Styles: Match your email’s look to your website’s branding.
- Insert Clickable Links: Present links as buttons or stylized text instead of raw URLs.
🛠️ How to Set the Mail Type to HTML
You have a few straightforward methods to set the mail type to HTML. The best method depends on whether you’re comfortable editing code or prefer a plugin.
1. Using a WordPress Plugin (The Easiest Way)
The most user-friendly approach is to install a dedicated SMTP or Email Management plugin. Many of these plugins include an option to force HTML content type for all outgoing emails.
- WP Mail SMTP: A very popular plugin for configuring email sending. It often handles this setting automatically or provides a clear option within its settings to ensure better email delivery and HTML support.
- Better Email: Some smaller, dedicated plugins focus specifically on styling and formatting default WordPress emails, automatically setting the content type to HTML.
Action:
- Install and activate your chosen plugin (e.g., WP Mail SMTP).
- Navigate to the plugin’s settings page.
- Look for an option related to Content Type or Email Format and ensure it is set to HTML.
2. Using Code in Your Theme’s functions.php (Developer Approach)
If you’re comfortable adding a small snippet of code to your theme, you can force all WordPress-generated emails to use the HTML content type.
🚨 Safety First: Always use a Child Theme when editing the functions.php file. If you edit the main theme and it gets updated, your changes will be lost.
Add the following code snippet to your child theme’s functions.php file:
function set_html_content_type() {
return 'text/html';
}
add_filter( 'wp_mail_content_type', 'set_html_content_type' );Code language: JavaScript (javascript)
What this does: This code uses the wp_mail_content_type filter, which WordPress calls just before sending an email, and forces the content type to be text/html instead of the default text/plain.
⚠️ Don’t Forget to Remove It! The filter above sets the HTML type globally. If you want to revert to the default (or need to send a plain text email for a specific function), you must remove the filter after the mail is sent.
A more robust way for a one-time email might look like this (but for global site emails, the simple snippet above is usually fine):
// Only sets the filter, use the global version for site-wide HTML
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
wp_mail( 'recipient@example.com', 'Subject', '<html><body style="background-color: #f4f4f4;">...</body></html>' );
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );Code language: JavaScript (javascript)
📝 Testing Your New HTML Emails
After implementing your chosen method, it’s crucial to test that your emails are being sent correctly in HTML format.
- Use a Contact Form: Fill out your site’s contact form to trigger a notification email.
- Reset Password: Try to reset your WordPress password to trigger the system email.
- Check the Source: When you receive the test email, view the source code (most email clients have this option). You should see full HTML tags, not just plain text.
