PHPMailer SMTP
This module sends emails via SMTP using the PHPMailer library, supporting HTML emails, attachments, and inline images. It works with the Mail System module and requires an SMTP service for sending messages.
Send emails via SMTP using the latest PHPMailer library.
The only requirements are the Mail System module and an SMTP service.
Features
- Send email via SMTP using an external service
- Supports HTML emails, attachments and inline images
- RFC compliant ensuring robust email delivery
- Makes extensive use of the widely adopted, battle-tested PHPMailer library
- Debugging options
- Advanced SMTP settings
Requirements
- Access to an SMTP server
- The Mail System module.
- PHPMailer library - installed via composer, see below
Installation
composer require drupal/phpmailer_smtp
This installs the module and the PHPMailer library. Enable the module as usual.
If you can't use composer Ludwig is supported.
Configuration
Configure PHPMailer SMTP
SMTP server configuration
Administer -> Configuration -> System -> PHPMailer SMTP
The most secure port is 465 which uses implicit encryption so no part of the communication is in plain text. For this port, select "SSL/TLS" as the encryption protocol.
The "STARTTLS" option is used to upgrade a plain text connection to use TLS. This is used with port 587 which requires an explicit request to change to an encrypted connection and is less secure than the fully encrypted connection on port 465.
Email format
Administer -> Configuration -> System -> PHPMailer SMTP -> Format
Selecting "Plain text" will force all emails to be plain text.
Install and Configure Mail System
composer require drupal/mailsystem
Enable the mail system module then configure:
Administer -> Configuration -> System -> Mail System.
Select "PHPMailer SMTP" as "Sender" under "Default Mail System" and "Module-Specific Configuration" as required.
Select "PHPMailer SMTP" as the Formatter
Security
For better security, SMTP credentials can be stored outside normal config.
- The simplest option is a local
settings.phporsettings.local.phpwhich retrieves the credentials from an external service, such as AWS secrets manager. This is more secure than storing them in config, file or environment variables. - Key can override any configuration value with a key to store configuration values more securely. See Overriding configuration and key providers supported by the module.
- Encrypt adds encryption support with a patch for the Key module: #2980072: Encrypt key value
OAuth2
OAuth2 is supported via basic plugins. For an example using Azure, see PHPMailer OAuth2. Review the code in the module to find out how it works so you can implement your own provider.
PHPMailer Azure OAuth2 is a more mature module which integrates with PHPMailer SMTP.
The PHPMailer library supports league/oauth2-client providers:
As of PHPMailer 6.6.0, the library now accepts anything that implements the OAuthProviderInterface. This includes Google's OAuth classes.
Performance
To improve performance on page load emails can be queued prior to sending.
- Queue Mail will queue emails which can then be sent later on a cron run.
- Ultimate Cron allows for fine-grained control over cron runs. For example using Queue Mail, email can be stored and sent sent every minute while other tasks are performed once an hour.
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
Activity
Release Timeline
Releases
| Version | Type | Core | Notes | Release date | |
|---|---|---|---|---|---|
| 3.0.0 | Stable | 11 | Aug 7, 2026 | ||
| 2.4.1 | Stable | 10–11 | Jul 2, 2026 | ||
| 3.0.0-alpha1 | Pre-release | 11 | Jul 2, 2026 | ||
| 3.0.x-dev | Dev | 11 | Jul 2, 2026 | ||
| 2.4.x-dev | Dev | 10–11 | Oct 22, 2025 | ||
| 2.4.0 | Stable | 10–11 | PHPMailer 7.0.0 support. | Oct 15, 2025 | |
| 2.3.1 | Stable | 10–11 | Adds support for PHPMailer 6.11.x. | Oct 5, 2025 | |
| 2.3.0 | Stable | 10–11 | Sep 9, 2025 | ||
| 2.3.0-beta1 | Pre-release | 10–11 | Apr 28, 2025 | ||
| 2.3.x-dev | Dev | 10–11 | For Drupal 10.3.x and up. | Jan 9, 2025 |