Skip to content
Provides a clean and simple way to configure the WordPress-bundled PHPMailer library, allowing you to quickly get started sending mail through a local or cloud based service of your choice
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

WP PHPMailer

CircleCI Packagist Version WordPress Plugin Rating PHP from Packagist WordPress Plugin: Tested WP Version Packagist Downloads WordPress Plugin Downloads GitHub License Hire Itineris Twitter Follow @itineris_ltd Twitter Follow @TangRufus

WP PHPMailer provides a clean and simple way to configure the WordPress-bundled PHPMailer library, allowing you to quickly get started sending mail through a local or cloud based service of your choice.


Although WordPress bundles the PHPMailer library which allow you sending mail through a local or cloud based service of your choice, different cloud based service requires different configuration. Worse still, most services provide multiple ways for setting them up. For instance: which SendGrid SMTP port provides the highest level of security, 25, 587, 2525 or 465?

WP PHPMailer uses the WordPress-bundled PHPMailer library:

  • so you offload the responsibility of updating bundled libraries from plugin authors to WordPress core team and contributors
    • at the time of writing, the official SendGrid plugin's vendor folder hasn't been updated in 2.5 years

WP PHPMailer believes in convention over configuration, we pick the best configuration for each service:

  • so you don't waste time going through the documents
  • so you don't have to figure out which port and protocol to use
  • so you don't miss any security configuration, e.g: SMTPAuth, SMTPSecure, etc
  • so you only have to provide minimum information
    • take SendGrid for example, only SendGrid API key (with "Mail Send" permission only) is required

WP PHPMailer believes a plugin should "do one thing and do it well":


Pick one driver and define its required constants in wp-config.php.


define('WP_PHPMAILER_DRIVER', 'mailhog');


define('WP_PHPMAILER_DRIVER', 'mailtrap');

define('MAILTRAP_USERNAME', 'your-mailtrap-username');
define('MAILTRAP_PASSWORD', 'your-mailtrap-password');


define('WP_PHPMAILER_DRIVER', 'sendgrid');

define('SENDGRID_API_KEY', 'your-sendgrid-api-key');

// Optional. Useful if you have email authentication configurated.
define('SENDGRID_FROM_ADDRESS', 'you@example.test');
define('SENDGRID_FROM_NAME', 'John Doe');
define('SENDGRID_FROM_AUTO', true);

Custom Driver

Step 1. Define Your Driver

class MyCustomDriver implements DriverInterface
    public static function makeConfig(ConstantRepository $constantRepo): ConfigInterface
        $config = new Config();

        $config->set('auth', true);
        $config->set('host', 'smtp.custom.test');
        $config->set('port', 587);
        $config->set('protocol', 'tls');




        return $config;

Step 2. Register Your Driver

add_filter('wp_phpmailer_drivers', function (array $drivers): array {
    $drivers['my-custom-driver'] = MyCustomDriver::class;

    return $drivers;

Step 3. Define Constants

// wp-config.php

define('WP_PHPMAILER_DRIVER', 'my-custom-driver');

define('MY_CUSTOM_USERNAME', 'xxx');
define('MY_CUSTOM_PASSWORD', 'xxx');

// Optional.
define('MY_CUSTOM_FROM_ADDRESS', 'xxx');
define('MY_CUSTOM_FROM_NAME', 'xxx');
define('MY_CUSTOM_FROM_AUTO', true);



$driver = (string) apply_filters('wp_phpmailer_driver', string $wpPhpmailerDriver))

Filters the WP_PHPMAILER_DRIVER constant.


  • $wpPhpmailerDriver
    • (string) the value of WP_PHPMAILER_DRIVER constant


$drivers = (array) apply_filters('wp_phpmailer_drivers', array $drivers)

Filters the available drivers array.


  • $drivers
    • (array) the available drivers array


add_filter('wp_phpmailer_drivers', function (array $drivers): array {
   $drivers['my-custom-driver'] = MyCustomDriver::class;

   return $drivers;


$mappings = (array) apply_filters('wp_phpmailer_config_mappings', array $mapings)

Filters the whitelisted PHPMailer configuration (property names) array. 'fromAddress', 'fromName', 'fromAuto' are special. Do not add them in mappings!


  • $mapings
    • (array) the whitelisted PHPMailer configuration (property names)


add_filter('wp_phpmailer_config_mappings', function (array $mappings): array {
    $mappings['xxx'] = 'yyy';

    return $mappings;

// The above filter results in:
add_action( 'phpmailer_init', function (PHPMailer $phpmailer) {
    // $this->config comes from `DriverInterface::makeConfig`.
    $phpmailer->xxx = $this->config->get('yyy');

Minimum Requirements

  • PHP v7.2
  • WordPress v5.1


Composer (Recommended)

composer require itinerisltd/wp-phpmailer (WP CLI)

wp plugin install wp-phpmailer

Download from Then, install as usual.

Build from Source (Not Recommended)

# Make sure you use the same PHP version as remote servers.
# Building inside docker images is recommanded.
php -v

# Checkout source code
git clone
cd wp-phpmailer
git checkout <the-tag-or-the-branch-or-the-commit>

# Build the zip file
composer release:build

Then, install release/ as usual.

Common Errors

NotFoundException - Driver 'xxx' not found, acceptable values are: aaa, bbb, ccc

Reason: Driver is not found or not defined.


  • Ensure PHP constant is WP_PHPMAILER_DRIVER is correct
  • Ensure filter wp_phpmailer_driver is functioning correctly


Where is the settings page?

There is no settings page.

All configurations are done by PHP constants and WordPress filters.

Will you add a settings page?


We have seen countless vulnerabilities related to user inputs. Mail settings don't change often and should be configured by a developer. Therefore, WP PHPMailer decided to use PHP constants instead of storing options in WordPress database.

However, if you must, you can use filters to override this behavior.

What PHPMailer version bundled?

This plugin reuse the PHPMailer class bundled with WordPress core.

Thus, you have to keep WordPress core up to date to receive security patches.

Is it a must to use SMTP?


While you can make your own non-SMTP drivers, all default drivers are using SMTP. Pull requests are welcomed.

Will you add support for older PHP versions?

Never! This plugin will only work on actively supported PHP versions.

Don't use it on end of life or security fixes only PHP versions.

It looks awesome. Where can I find more goodies like this?

Where can I give ⭐️⭐️⭐️⭐️⭐️ reviews?

Thanks! Glad you like it. It's important to let my boss knows somebody is using this project. Please consider:


composer test
composer phpstan:analyse
composer style:check

Pull requests without tests will not be accepted!


Please provide feedback! We want to make this library useful in as many projects as possible. Please submit an issue and point out what you do and don't like, or fork the project and make suggestions. No issue is too small.

Change Log

Please see CHANGELOG for more information on what has changed recently.


If you discover any security related issues, please email instead of using the issue tracker.


WP PHPMailer is a Itineris Limited project created by Tang Rufus.

Special thanks to Brandon whose WP SMTP inspired this project.

Full list of contributors can be found here.


WP PHPMailer is released under the MIT License.

You can’t perform that action at this time.