API first, responsive Bartik, headless and decoupled Drupal, Layout Builder, React admin UI... Drupal's evolved tremendously over these 18 years! Yet: the emails that we send out via its otherwise robust email sending system aren't different from those we used to send a... decade ago. And customers expect rich experiences outside your Drupal website or app. While website administrators expect to be enabled to easily manage, via the admin UI, their email content templates. So: how do you send HTML emails in Drupal 8?
Without relying on external services, of course...
And who could blame customers for expecting 2019-specific user experiences? Experiences that HTML-enabled emails deliver through their great features.
Features that support Drupal editors' marketing efforts, as well:
- traffic-driving hyperlinks; you get to link to your landing page right from the email
- visually attractive custom design; emails that look just like some... microsites
- all sorts of design details that reinforce your brand: buttons over cryptic links, responsive design, templated footers and headers
- web fonts
- QR codes
- hierarchical display of content, that enhances readability and draws attention to key pieces of content and links in your email
- images and attachments
- tracking for monitoring opens
And speaking of admin and/or editors, the questions they ask themselves are:
“How can I easily theme the emails to be sent out?”
“How can I change their content templates right from the admin UI?”
And these are the questions that I'll be answering to in this post.
Here are your current options at hand — 3 useful Drupal 8 modules — for easily crafting and sending out HTML emails that appeal and engage.
1. The HTML Mail Module
It does exactly what you'd expect:
It enables you to configure HTML emails from Drupal 8.
It's the Drupal 7 go-to option whenever you want to go from plain text emails to HTML-formatted ones. A module available for Drupal 8 in alpha version.
Furthermore, it integrates superbly with the Echo and the Mail MIME modules.
2. The Swift Mailer Module, The Best Way to Send HTML Emails in Drupal 8
Swift Mailer is the highly recommended method for configuring Drupal 8 to send out visually-arresting, HTML emails.
Since you can't (yet) send them right out of the box with Drupal...
The module stands out as the best option at hand with some heavy-weighing features:
- it supports file attachments
- it supports inline images, as well
- it enables admins to send HTML (MIME) emails
- … to send them out via an SMTP server, the PHP-provided mail sending functionality or via a locally installed MTA agent
Note: you even get to use this module in tandem with Commerce to send out your HTML-enabled emails. There's even an initiative underway for replacing Drupal's deprecated core mail system with the Swift Mailer library.
And now, here are the major configuration steps to take to... unleash and explore this module's capabilities:
- first, set up the Swift Mailer message (/admin/config/swiftmailer/messages) settings to use HTML
- next, configure the Swift Mailer transport settings (/admin/config/swiftmailer/transport) to your transport method of choice
- and finally, configure the core mail system settings to use this module for the formatter and the sender plugins
And if you're not yet 100% convinced that the Swift Mailer module is significantly superior to Drupal's default mail system, here are some more arguments:
- it enables you to send... mixed emails: both plain text and HTML-enabled
- it provides HTML content types
- it supports various transport methods: Sendmail, PHP, SMTP (the current mail system supports but one method)
- it enables you to integrate key services with Drupal — like Mandrill, SendGrid — right out of the box
- it incorporates a pluggable system, allowing you to further extend its functionality
How about now? Are these strong enough arguments that Swit Mailer's the way to send HTML emails in Drupal 8?
3. The PHPMailer Module
Another option for configuring Drupal 8 to send out HTML emails is the PHPMailer module.
How does it perform compared to Swift Mailer?
- It's not pluggable
- it's not as easily customizable as Swift Mailer
- it's already embedded in the SMTP module (in fact, in Drupal 8 the default mail interface class is named “PHPMail” instead of DefaultMailSystem)
What features does it share with Swift Mailer?
- it enables you to send out HTML-enabled emails with Drupal
- it enables you to add attachments to your emails
- it, too, enables you to send out mixed emails
- it, too, supports external SMTP servers
Moreover, you can extend its core functionality by integrating it with the Mime Mail component module (currently in alpha 2 version for Drupal 8).
4. The Mime Mail Component Module
Briefly, just a few words about Mime Mail:
- as already mentioned, it's a “component module”, that can be used for boosting other modules' functionality
- it enables you to send out HTML emails with Drupal: your mail would then incorporate a mime-encoded HTML message body
- it enables you to set up custom email templates: just go to your mimemail/theme directory, copy the mimemail-message.tpl.php file and paste it into your default theme's folder; this way, your email will take over your website's design style
- any embedded graphics gets Mime-encoded, as well, and added as an attachment to your HTML email
- do some of your recipients prefer plain text over richly formatted HTML emails? Mime Mail enables you to switch your email content over to plain text to meet their specific preferences
Now that you know your options, it's time to step out from the (too) long era of rudimentary, plain emails sent out with Drupal.
... and into the era of richly formatted HTML emails, that will:
- enrich your customers' experiences
- enhance Drupal 8 site admins' experience
We do Web development
Go to our Web development page!