Sending reliable email notifications from Drupal is essential for contact forms, service inquiries, and other user submissions. This guide explains how to properly configure Drupal 10 and 11 to send HTML emails using Webform handlers, the Mail System module, and optionally the SMTP module for authenticated delivery.

This configuration ensures that all Webform submissions are formatted, delivered securely, and reach the intended recipients.


1. Modules required

Before configuring email delivery, make sure the following modules are installed and enabled:

Install them using Composer:

composer require drupal/webform drupal/mailsystem drupal/smtp

Enable the modules:

drush en webform mailsystem smtp -y

2. Configure the SMTP module

If you plan to use a third-party mail server such as Microsoft 365, Gmail, or another authenticated SMTP provider, configure the SMTP module.

Go to:
Configuration → System → SMTP Authentication Support

SettingExample
SMTP serversmtp.office365.com or smtp.gmail.com
SMTP port587
Use TLS encryption✔ Checked
Usernameyour email address
Passwordyour app or mail password
E-mail from addresssame as above
E-mail from nameyour company name
Allow to send e-mails formatted as HTML✔ Checked

Example for Microsoft Outlook SMTP mail sending

configure-SMTP-drupal-module-for-outlook-webmail

💡 Make sure your web server allows outbound connections on port 587 or the SMTP port required by your mail provider.


3. Configure the Mail System module

Go to:
Configuration → System → Mail System

Use the following recommended working configuration for Webform-based emails:

SettingValue
Default Mail System
FormatterWebform PHP mailer
SenderWebform PHP mailer
ThemeDefault
Module-specific configuration
Module: WebformFormatter: Webform PHP mailer
Sender: Webform PHP mailer
Module: Contact (optional)Formatter: Webform PHP mailer
Sender: Webform PHP mailer

Why this works

  • Uses Webform’s internal mailer for clean HTML rendering.

  • Maintains HTML structure in emails.

  • Compatible with both the PHP mailer and SMTP sender.

drupal-configure-mail-system-settings-for-webform


4. Set up or update your Webform handler

Go to:
Structure → Webforms → [Your Webform] → Emails / Handlers

Click Edit or Add Email Handler and configure:

SettingExample Value
ToRecipient email address
BCCOptional additional recipients
From[name] <no-reply@yourdomain.com>
Reply to[email]
SubjectService inquiry or contact form submission
Send email asHTML
Send whenCompleted

Sample:

configure-drupal-webform-handlers-for-email-sending

5. Add custom HTML message and submission data

In the Message field of your Webform handler, you can include your own HTML layout and submission tokens.

Example using the custom Twig formatter in the handler Body settings:

<p>Thanks for your message. Our team will get back to you shortly with any additional details they might need.</p>
<p>Submitted on {{ webform_token('[webform_submission:created]', webform_submission, [], options) }}</p>
<p>Submitted by: {{ webform_token('[webform_submission:user]', webform_submission, [], options) }}</p>
<p>Submitted values are:</p>
{{ webform_token('[webform_submission:values]', webform_submission, [], options) }}

📌 The token [webform_submission:values:html] automatically includes all submitted form fields with HTML formatting.


6. Test your configuration

  1. Visit the page containing your Webform.

  2. Submit a test message.

  3. Check the recipient inbox or spam folder.

  4. Review logs at /admin/reports/dblog if no message is received.

If you receive the email with proper formatting (paragraphs, links, line breaks), the configuration is working.


7. Optional: Combine HTML formatting with SMTP delivery

If you want to use SMTP for the actual sending process while keeping HTML formatting handled by Webform, adjust the Mail System settings:

SettingValue
FormatterWebform PHP mailer
SenderSMTP Mailer

This ensures Webform continues to format emails as HTML, while SMTP handles delivery securely through your chosen mail server.


8. Troubleshooting

Emails appear as plain text:
– Ensure the handler is set to send as HTML.
– Verify the Mail System formatter is Webform PHP mailer.

Emails not sending:
– Double-check SMTP credentials and ports.
– Test using the PHP mailer to isolate SMTP issues.

Emails duplicated or inconsistently formatted:
– Avoid conflicting Mail System configurations across modules.


Summary

ModulePurposeRecommended Plugin
WebformManages form creation and submission handlersWebform PHP mailer
Mail SystemControls mail formatting and sending logicWebform PHP mailer
SMTPProvides authenticated email deliverySMTP Mailer (optional)

This combination provides a stable and flexible way to send HTML-formatted emails from Drupal Webforms, compatible with both native mail and SMTP-based systems.