Mailgate SMTP
WP must-use plugin that sends all mail through SMTP configured with wp-config constants
by synchronicity.one · github.com/synchronicity-one/wp-torwald45-mailgate
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/synchronicity-one/wp-torwald45-mailgate/archive/refs/heads/main.zipA WP must-use plugin that sends all mail through an SMTP server configured with constants in wp-config.php. It has no admin screen and stores nothing in the database, so it can not be changed or disabled from the admin panel.
What it does
- Sends every message that goes through wp_mail (WP core, Woo, form plugins) over SMTP with authentication.
- Applies its settings at the last phpmailer_init priority, so sender changes made by other plugins or by Woo are overridden right before sending.
- Uses the SMTP mailbox as the sender in the From header and in the envelope. SMTP servers usually reject senders that do not belong to the authenticated mailbox.
- Keeps the sender name set by a plugin, for example the Woo store name. The core default sender name is replaced by TORWALD45_MAILGATE_FROM_NAME or by the site name.
- Moves the original sender address to Reply-To when a plugin set a different sender and no Reply-To, so replies reach the intended address. The core default sender address is not used as Reply-To.
- Logs failed deliveries without credentials.
Requirements
- PHP 7.4 or newer
- WP 5.5 or newer (PHPMailer 6)
- An SMTP account
Installation
Copy the file to the must-use plugins directory:
wp-content/mu-plugins/torwald45-mailgate.php
Install a pinned release and verify its checksum. Example for v1.0, checksums of all releases are listed in CHANGELOG.md:
curl -fsSL -o torwald45-mailgate.php https://raw.githubusercontent.com/synchronicity-one/wp-torwald45-mailgate/v1.0/torwald45-mailgate.php
echo "8b830655db782f1aba18bac819e897dc266d3919f2e0f3d5072f36692eca7230 torwald45-mailgate.php" | sha256sum -c -
The file must be readable by the PHP process.
Configuration
Required constants in wp-config.php:
define( 'TORWALD45_MAILGATE_HOST', 'mail.example.com' );
define( 'TORWALD45_MAILGATE_USER', 'noreply@example.com' );
define( 'TORWALD45_MAILGATE_PASS', 'secret' );
Optional constants:
| Constant | Default | Meaning |
|---|---|---|
| TORWALD45_MAILGATE_PORT | 587 | SMTP port |
| TORWALD45_MAILGATE_SECURE | tls | tls, ssl or none |
| TORWALD45_MAILGATE_FROM | value of TORWALD45_MAILGATE_USER | Sender address |
| TORWALD45_MAILGATE_FROM_NAME | site name | Replaces the core default sender name |
| TORWALD45_MAILGATE_TIMEOUT | 20 | SMTP timeout in seconds |
| TORWALD45_MAILGATE_LOG_FILE | PHP error log | Log file path |
With WP-CLI:
wp config set TORWALD45_MAILGATE_HOST mail.example.com
wp config set TORWALD45_MAILGATE_PORT 587 --raw
wp config set TORWALD45_MAILGATE_USER noreply@example.com
wp config set TORWALD45_MAILGATE_PASS 'secret'
When a required constant is missing or a value is invalid, the plugin leaves mail unchanged and logs a warning.
WP-CLI commands
wp torwald45-mailgate status
wp torwald45-mailgate test recipient@example.com
status prints the configuration without the password. It warns when wp_mail is replaced by other code or when another mail plugin is active.
test sends a test message and prints the SMTP dialogue. Credentials in the dialogue are masked by PHPMailer.
Logging
Entries start with [torwald45-mailgate]. By default they go to the PHP error log, in Docker images usually the container log. Define TORWALD45_MAILGATE_LOG_FILE to write to a file instead. When the file is not writable, the entry goes to the PHP error log.
Compatibility
- Do not run it together with other SMTP plugins. Plugins that replace wp_mail bypass phpmailer_init and therefore this plugin.
- Mail sent without wp_mail is not covered.
License
GPL-2.0-or-later. See LICENSE.