Whenever I post a tutorial about sending emails using Drupal, the first question I get asked is how to send emails as HTML. By default, emails are sent as plain text in Drupal 7. There are a few modules out there that allow you to send emails as HTML like Mime Mail, HTML Mail and Swift Mailer.
There are a few benefits in sending emails as HTML. For one thing, they can be styled and images can be displayed. Also, it’s easier to track open rates and clicks if the email is HTML. However, there are some downsides to using HTML. One thing I’ve read about is that HTML emails are more likely to be flagged as spam. Especially if your whole email is just a single image.
If you prefer Drush, run the following command:
drush dl rules entity mimemail mailsystem
Once everything has been downloaded, enable Mail System, Mime Mail, Rules and Rules UI.
Step 1: Configure Mail System
So head over to Configuration, “Mail System” and make sure that
MimeMailSystem has been selected in the “Site-wide default MailSystemInterface class” and “Mime Mail module class” drop-down list.
Step 2: Configure Mime Mail
Now, head over to Configuration and click on “Mime Mail”. From this page you can change a few of the module’s configuration options. The one we’re interested in, for now, is the “E-mail format”.
Change it from “Plain text” to “Filter HTML”. This means that when emails are sent they’ll be filtered by the “Filter HTML” text format.
At this point, you should be able to send HTML emails. If certain tags are being filtered out, make sure that the text format selected in “E-mail format” allows the tags.
Send HTML Emails using Rules
Mime Mail integrates beautifully with Rules. The module implements two custom actions: “Send HTML e-mail” and “Send HTML mail to all users of a role”. As you may have guessed, both actions allow you to send emails as HTML.
I won’t go through the process of creating a basic rule. I’ll assume you’ve already created one. So go and edit a rule that will send an email.
Click on “Add action” and select “Send HTML e-mail” or “Send HTML mail to all users of a role” from the drop-down list.
As you can see, sending HTML emails from Drupal is not that hard. However, if you’re emails are still being sent as plain text and you have a lot of modules installed start reviewing your existing setup. Occasionally, a module might change some mail setting that prevents an email from being sent as HTML.
Q: Emails are not being sent as HTML.
Double check the “E-mail format” option in Mime Mail and make sure it’s not set to “Plain text”.
Q: Emails are not being sent at all.
First make sure you’ve setup a local mail server to send emails. Without a mail server or a 3rd party SMTP provider, emails will not magically be sent. Also, look in the watchdog table for PHP or mail errors.
Q: Rules is not sending emails.
First, make sure your rule is being executed. Once you’ve confirm this, then make sure that you’re using the “Send HTML e-mail” or “Send HTML mail to all users of a role” action.
Q: I’m getting “Unable to send e-mail. Contact the site administrator if the problem persists.”, please help!
This means Drupal got an error trying to send an email. Chances are your mail server is not setup properly.
Q: How do I setup an email server on Windows/Linux/Mac?
An email server can be setup in many ways, you should be able to find a tutorial on the internet.