All Projects → ItinerisLtd → Wp Phpmailer

ItinerisLtd / Wp Phpmailer

Licence: mit
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

Projects that are alternatives of or similar to Wp Phpmailer

Magento2 Gmail Smtp App
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers
Stars: ✭ 281 (+510.87%)
Mutual labels:  office365, smtp, sendgrid
wemail
Send Affordable Bulk Email Campaign Through WordPress
Stars: ✭ 19 (-58.7%)
Mutual labels:  wordpress-plugin, smtp, sendgrid
Wordpress
Docker based Wordpress deployment using a collection of optimized containers w/ Nginx, PHP-FPM, MariaDB and Redis.
Stars: ✭ 44 (-4.35%)
Mutual labels:  wordpress, wordpress-plugin
Ultimate Blocks
Custom Gutenberg Blocks for Bloggers and Marketers. Create Better Content With Gutenberg.
Stars: ✭ 29 (-36.96%)
Mutual labels:  wordpress, wordpress-plugin
Cloud Blocks
WP plugin for Gutenberg Cloud – Your library of blocks in the cloud!
Stars: ✭ 44 (-4.35%)
Mutual labels:  wordpress, wordpress-plugin
Geodirectory
GeoDirectory is the fastest growing Directory plugin for WordPress. Feel free to contribute or suggest new developments and help us take GD to the next level. http://wpgeodirectory.com | http://wordpress.org/plugins/geodirectory/
Stars: ✭ 41 (-10.87%)
Mutual labels:  wordpress, wordpress-plugin
Builder Template Categories
Organize your Page Builder Templates in the WordPress Admin. Time saver, especially for bigger projects. Get a better and faster overview, don't get lost. Filter templates with your categories. With extended plugin & theme support.
Stars: ✭ 20 (-56.52%)
Mutual labels:  wordpress, wordpress-plugin
Wp2static
WordPress static site generator for security, performance and cost benefits
Stars: ✭ 952 (+1969.57%)
Mutual labels:  wordpress, wordpress-plugin
Wp Downloadmanager
Adds a simple download manager to your WordPress blog.
Stars: ✭ 11 (-76.09%)
Mutual labels:  wordpress, wordpress-plugin
Einsatzverwaltung
WordPress plugin for public incident reports for fire departments and other rescue services
Stars: ✭ 32 (-30.43%)
Mutual labels:  wordpress, wordpress-plugin
Afb instant articles
allfacebook Instant Articles - The WordPress Plugin for facebook instant articles.
Stars: ✭ 31 (-32.61%)
Mutual labels:  wordpress, wordpress-plugin
Tribe Common
Common classes and functions used in our plugins
Stars: ✭ 38 (-17.39%)
Mutual labels:  wordpress, wordpress-plugin
Wordpress Related
WordPress codes
Stars: ✭ 15 (-67.39%)
Mutual labels:  wordpress, wordpress-plugin
Pods
The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
Stars: ✭ 883 (+1819.57%)
Mutual labels:  wordpress, wordpress-plugin
Fancy Product Designer Extended
Updated fancy product designer plugin
Stars: ✭ 21 (-54.35%)
Mutual labels:  wordpress, wordpress-plugin
Wp Hercules
Simple domain mapping for top domains
Stars: ✭ 13 (-71.74%)
Mutual labels:  wordpress, wordpress-plugin
Wordpress To Jekyll Exporter
One-click WordPress plugin that converts all posts, pages, taxonomies, metadata, and settings to Markdown and YAML which can be dropped into Jekyll
Stars: ✭ 951 (+1967.39%)
Mutual labels:  wordpress, wordpress-plugin
Wp Shopify
🎉 Sell and build custom Shopify experiences on WordPress.
Stars: ✭ 38 (-17.39%)
Mutual labels:  wordpress, wordpress-plugin
Better Search
Better Search WordPress plugin
Stars: ✭ 9 (-80.43%)
Mutual labels:  wordpress, wordpress-plugin
Momtaz Nmwdhj
A WordPress forms elements API plugin.
Stars: ✭ 11 (-76.09%)
Mutual labels:  wordpress, wordpress-plugin

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.

Goal

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":

Usage

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

Mailhog

define('WP_PHPMAILER_DRIVER', 'mailhog');

Mailtrap

define('WP_PHPMAILER_DRIVER', 'mailtrap');

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

SendGrid

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', '[email protected]');
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');

        $config->set(
            'username',
            $constantRepo->getRequired('MY_CUSTOM_USERNAME')
        );

        $config->set(
            'password',
            $constantRepo->getRequired('MY_CUSTOM_PASSWORD')
        );

        $config->set(
            'fromAddress',
            $constantRepo->get('MY_CUSTOM_FROM_ADDRESS')
        );
        $config->set(
            'fromName',
            $constantRepo->get('MY_CUSTOM_FROM_NAME')
        );
        $config->set(
            'fromAuto',
            $constantRepo->get('MY_CUSTOM_FROM_AUTO')
        );

        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);

Filters

wp_phpmailer_driver

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

Filters the WP_PHPMAILER_DRIVER constant.

Parameters:

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

wp_phpmailer_drivers

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

Filters the available drivers array.

Parameters:

  • $drivers
    • (array) the available drivers array

Example:

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

   return $drivers;
});

wp_phpmailer_config_mappings

$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!

Parameters:

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

Example:

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.5

Installation

Composer (Recommended)

composer require itinerisltd/wp-phpmailer

wordpress.org (WP CLI)

wp plugin install wp-phpmailer

wordpress.org

Download from https://wordpress.org/plugins/wp-phpmailer Then, install wp-phpmailer.zip as usual.

Build from Source (Not Recommended)

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

# Checkout source code
git clone https://github.com/ItinerisLtd/wp-phpmailer.git
cd wp-phpmailer
git checkout <the-tag-or-the-branch-or-the-commit>

# Build the zip file
composer release:build

Then, install release/wp-phpmailer.zip as usual.

Common Errors

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

Reason: Driver is not found or not defined.

Troubleshooting:

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

FAQ

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?

No.

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?

No.

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:

Testing

composer test
composer phpstan:analyse
composer style:check

Pull requests without tests will not be accepted!

Feedback

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.

Security

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

Credits

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.

License

WP PHPMailer is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].