Skip to content

WordPress

Guide for sites running WordPress 6.x. Mailexam connects as an SMTP server through built-in wp_mail() and the phpmailer_init hook (PHPMailer).

What you need

  • A Mailexam account and a project with SMTP credentials.
  • WordPress 6+ and PHP 8.0+.

Copy from the welcome email (or dashboard) for your project:

  • YOUR_LOGIN — SMTP login (for example, xxxxx);
  • YOUR_PASSWORD — SMTP password (a unique pair with the login);
  • host — YOUR_LOGIN.mailexam.io (the hostname matches the login).

1. Constants in wp-config.php

Add before /* That's all, stop editing! */ (do not commit passwords to a public repository):

define('MAILEXAM_LOGIN', 'YOUR_LOGIN');
define('MAILEXAM_PASSWORD', 'YOUR_PASSWORD');
define('MAILEXAM_PORT', 587);
define('MAIL_FROM', 'noreply@example.test');

SMTP host: YOUR_LOGIN.mailexam.io.

Sender address

MAIL_FROM can be any test address — the message still goes to Mailexam, not to a real recipient.

Alternative ports

define('MAILEXAM_PORT', 587);

In the MU plugin: $phpmailer->SMTPSecure = 'tls';

define('MAILEXAM_PORT', 2525);
define('MAILEXAM_PORT', 465);

$phpmailer->SMTPSecure = 'ssl';

define('MAILEXAM_PORT', 25);

$phpmailer->SMTPSecure = '';

2. SMTP must-use plugin

Create wp-content/mu-plugins/mailexam-smtp.php (create the mu-plugins folder if missing):

<?php
/**
 * Plugin Name: Mailexam SMTP
 * Description: Send WordPress mail via Mailexam SMTP
 */

add_action('phpmailer_init', static function ($phpmailer): void {
    if (!defined('MAILEXAM_LOGIN') || !defined('MAILEXAM_PASSWORD')) {
        return;
    }

    $login = MAILEXAM_LOGIN;
    $port = defined('MAILEXAM_PORT') ? (int) MAILEXAM_PORT : 587;

    $phpmailer->isSMTP();
    $phpmailer->Host = $login . '.mailexam.io';
    $phpmailer->Port = $port;
    $phpmailer->SMTPAuth = true;
    $phpmailer->Username = $login;
    $phpmailer->Password = MAILEXAM_PASSWORD;

    if ($port === 465) {
        $phpmailer->SMTPSecure = 'ssl';
    } elseif (in_array($port, [587, 2525], true)) {
        $phpmailer->SMTPSecure = 'tls';
    } else {
        $phpmailer->SMTPSecure = '';
    }
});

add_filter('wp_mail_from', static function (): string {
    return defined('MAIL_FROM') ? MAIL_FROM : 'noreply@example.test';
});

Must-use plugins load automatically — no activation in the admin UI is required.

3. Test send

Via code (temporary snippet in the theme functions.php)

add_action('init', static function (): void {
    if (!isset($_GET['mailexam_mail_test']) || !current_user_can('manage_options')) {
        return;
    }

    $sent = wp_mail(
        'user@example.test',
        'WordPress + Mailexam',
        'Mailexam test from WordPress'
    );

    wp_die($sent ? 'Sent' : 'Failed');
});

Open in the browser (as an administrator):
https://your-site.test/?mailexam_mail_test=1

Remove this snippet after verification.

Via WP-CLI

wp eval "var_export(wp_mail('user@example.test', 'Check', 'Hello from WordPress'));"

The message appears in Mailexam dashboard → your project → inbox.

4. Local development and CI

Environment Recommendation
local constants in wp-config.php or wp-config-local.php
CI secrets MAILEXAM_LOGIN, MAILEXAM_PASSWORD in pipeline variables

Example for .gitlab-ci.yml:

variables:
  MAILEXAM_LOGIN: $MAILEXAM_LOGIN
  MAILEXAM_PASSWORD: $MAILEXAM_PASSWORD
  MAILEXAM_PORT: "587"
  MAIL_FROM: "noreply@example.test"

After an integration test, verify delivery via the Mailexam API.

5. Common issues

Mail does not use SMTP

  • Ensure the file is in wp-content/mu-plugins/, not plugins/.
  • Check that another SMTP plugin does not override phpmailer_init with a later priority.

TLS or authentication failed

  • Host must be {login}.mailexam.io, Username the same login from the email.
  • Login and password are a pair from one project welcome email.

Message not in the dashboard

  • Open inbox for the same Mailexam project.
  • Enable define('WP_DEBUG', true); and temporarily use WP Mail Logging for diagnostics.

See also