PHPackages                             markei/wordpress-smtp-configuration - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. markei/wordpress-smtp-configuration

ActiveWordpress-plugin[Mail &amp; Notifications](/categories/mail)

markei/wordpress-smtp-configuration
===================================

Configure WordPress for sending mail via SMTP mail supporting encryption, (basic) auth and xoauth2. Configuration is done via wp-config.php.

v1.3.0(9mo ago)1349MITPHPPHP &gt;=8.1.0

Since Nov 25Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/Markei/wordpress-smtp-configuration)[ Packagist](https://packagist.org/packages/markei/wordpress-smtp-configuration)[ Docs](https://github.com/Markei/wordpress-smtp-configuration)[ RSS](/packages/markei-wordpress-smtp-configuration/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Markei SMTP configuration for Wordpress
=======================================

[](#markei-smtp-configuration-for-wordpress)

Configure WordPress for sending mail via SMTP mail supporting encryption, (basic) auth and xoauth2. Configuration is done via wp-config.php.

For SMTP is supports plain connections but also SSL/TLS encryption (SMTPS) and STARTLS encryption. Authentication is possible via normal authentication (basic) and XOAUTH2. For XOAUTH2 authentification as a user (Authorization Code Flow) or service principal (Client Credential Flow) is possible. This makes it possible to mail via Gmail or Microsoft 365.

In the WordPress admin interface an e-mail test tool will become available to view the given configuration and let you sent a test mail.

This plugin is free, does not add signatures to your mail, no spam and no ad's.

How to
------

[](#how-to)

Activate the plugin in WordPress admin.

Add the next line to `wordpress/wp-config.php` above `require_once(ABSPATH . 'wp-settings.php');`

```
define('SMTP', 'smtp://localhost');

```

### Supported options

[](#supported-options)

The configuration supports a URL format. Example: `protocol://host:port?optionA=valueA&optionB=valueB`.

#### Protocol SMTP

[](#protocol-smtp)

Simple configuration, no auth, port 25

```
define('SMTP', 'smtp://localhost');

```

Simple configuration, no auth, with another port

```
define('SMTP', 'smtp://my-smtp-server:587');

```

With basic authentication, insecure because no encryption is set so username and password are send readable

```
define('SMTP', 'smtp://localhost:587?username=my-username&password=my-password');

```

Prefered way for authentification with STARTTLS encryption

```
define('SMTP', 'smtp://localhost:587?encryption=tls&username=my-username&password=my-password');

```

Prefered way for authentification with SMTPS encryption. Note encryption=ssl even the server uses a TLS protocol instead of and old-SSL protocol.

```
define('SMTP', 'smtp://localhost:465?encryption=ssl&username=my-username&password=my-password');

```

##### XOAUTH2 with client credentials (e.g. Microsoft 365)

[](#xoauth2-with-client-credentials-eg-microsoft-365)

Define `client_id`, `client_secret`, `token_endpoint` and `scope` as parameters. A access token is requested from the token\_endpoint each time a mail is sent.

> This is a good guide for [setting up a service principal for SMTP mailing in Microsoft 365/Office 365/Outlook Online/Exchange Online](https://www.maartendekeizer.nl/blog/detail/setup-smtp-xoauth2-with-microsoft-365). For 365 use server `smtp.office365.com`, port `587`, `token_endpoint=https://login.microsoftonline.com//oauth2/v2.0/token` and `scope=https://outlook.office365.com/.default`.

Caching can be enabled via the option cache=1, this will speed up the processes for sending mails becauses not for each mail a new token is requested. The access token is cached using the WordPress transient system.

```
define('SMTP', 'smtp://localhost:587?auth=xoauth2&client_id=my-client-id&client_secret=my-client-secret&token_endpoint=https://my-oauth-server/token&scope=sendmail&cache=1');

```

Example for Microsoft 365

```
define('SMTP', 'smtp://smtp.office365.com:587?auth=xoauth2&client_id=&client_secret=&token_endpoint=https://login.microsoftonline.com//oauth2/v2.0/token&scope=https://outlook.office365.com/.default&cache=1');

```

##### XOAUTH2 with authorization code flow (e.g. Gmail)

[](#xoauth2-with-authorization-code-flow-eg-gmail)

The plugin will use the following redirect\_uri which much be configured in the Authorization server:

```
https://my-wordpress-website.tld/wp-content/plugins/smtp-configuration/oauth2-callback.php

```

Define `client_id`, `client_secret`, `token_endpoint`, `auth_endpoint` and `scope` as parameters. Extra parameters for the authorization server can be set via `auth_endpoint_parameters` which accepts an key-value array.

> For Gmail use server `smtp.gmail.com`, port `587`, `token_endpoint=https://oauth2.googleapis.com/token`, `auth_endpoint=https://accounts.google.com/o/oauth2/auth`, `auth_endpoint_parameters[prompt]=consent&auth_endpoint_parameters[access_type]=offline` and `scope=https://mail.google.com/`.

Caching can be enabled via the option cache=1, this will speed up the processes for sending mails becauses not for each mail the refresh token is rotated. The access token is cached using the WordPress transient system.

```
define('SMTP', 'smtp://smtp.gmail.com:587?auth=xoauth2&client_id=my-client-id&client_secret=my-client-secret&token_endpoint=https://my-oauth-server/token&scope=sendmail%20offline&auth_endpoint=https://my-oauth-server/auth&cache=1');

```

Example for Gmail (replace your client id and secret):

```
define('SMTP', 'smtp://smtp.gmail.com:587?auth=xoauth2&client_id=&client_secret=&token_endpoint=https://oauth2.googleapis.com/token&scope=https://mail.google.com/&auth_endpoint=https://accounts.google.com/o/oauth2/auth&cache=1&auth_endpoint_parameters[prompt]=consent&auth_endpoint_parameters[access_type]=offline');

```

After configuration and enabling the plugin go to the SMTP configuration page in the Tools menu in the WordPress admin. Click on the *Obtain token* button.

#### Protocol Sendmail

[](#protocol-sendmail)

No options are available.

```
define('SMTP', 'sendmail://');

```

#### Protocol mail

[](#protocol-mail)

No options are available.

```
define('SMTP', 'mail://');

```

#### Debug

[](#debug)

Add the option `debug=1` to show debug information from PHPMailer. Don't enabled this in production it can contain secret information.

Install via composer
--------------------

[](#install-via-composer)

Install the plugin via Composer

```
composer require markei/wordpress-smtp-configuration

```

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance59

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~809 days

Total

4

Last Release

291d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.1.0

v1.2.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b5dd1f24f7aa6171a6aba04306eeab4cf4f18fd7d4ca43e9439845415c7c9ba8?d=identicon)[markei](/maintainers/markei)

---

Top Contributors

[![maartendekeizer](https://avatars.githubusercontent.com/u/1061334?v=4)](https://github.com/maartendekeizer "maartendekeizer (10 commits)")

---

Tags

wordpresswordpress pluginsmtpxoauth2

### Embed Badge

![Health badge](/badges/markei-wordpress-smtp-configuration/health.svg)

```
[![Health](https://phpackages.com/badges/markei-wordpress-smtp-configuration/health.svg)](https://phpackages.com/packages/markei-wordpress-smtp-configuration)
```

###  Alternatives

[nette/mail

📧 Nette Mail: A handy library for creating and sending emails in PHP.

5389.8M244](/packages/nette-mail)[humanmade/aws-ses-wp-mail

WordPress plugin to send mail via SES

188250.3k3](/packages/humanmade-aws-ses-wp-mail)[itinerisltd/wp-phpmailer

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

6231.6k](/packages/itinerisltd-wp-phpmailer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
