Search by

arraypress / wp-email-utils

arraypress

An immutable value object for working with email addresses in WordPress — parsing, validation, transformation, classification and analysis.

Package info

github.com/arraypress/wp-email-utils

pkg:composer/arraypress/wp-email-utils

Statistics

Installs: 161

Dependents: 1

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-08-25 15:44 UTC

This package is auto-updated.

Last update: 2026-09-02 16:26:16 UTC


README

An email address as a value object, so the fiddly questions have answers.

What it does

is_email() tells you whether an address is syntactically valid. Almost every real question is a different one: are dave+shop@gmail.com and d.a.v.e@gmail.com the same person signing up twice, is info@ a role mailbox rather than a human, did someone type gmial.com, does the domain accept mail at all.

Parse once into an Email, then ask. It is immutable, so the transformations hand back a new instance rather than changing the one you have.

Features

  • Compare two addresses as the same person, ignoring subaddresses and Gmail dots
  • Spot role mailboxes — info@, sales@, admin@ — that are not individuals
  • Catch common domain typos and suggest the correction
  • Check the domain actually has an MX record before accepting a signup
  • Recognise educational and government addresses, for discounts or verification
  • Add, replace or strip a +tag subaddress
  • Mask an address for display: d••••e@example.com
  • Match against wildcard patterns, for allow and block lists

Installation

composer require arraypress/wp-email-utils

Quick start

use ArrayPress\EmailUtils\Email;

$email = Email::parse( $_POST['email'] );

if ( ! $email ) {
    return new WP_Error( 'invalid_email', 'That address is not valid.' );
}

// Did they mean gmail.com?
if ( $email->has_typo() ) {
    $suggestion = $email->suggested_email();
}

// Is this the same customer signing up again with a +tag?
if ( $email->equals_base( $existing_customer_email ) ) {
    // ...
}

// Route role mailboxes differently from real people.
if ( $email->is_role_based() ) {
    // ...
}

// Show it in the admin without showing all of it.
echo esc_html( $email->to_masked() );

Requirements

  • PHP 8.3 or later
  • WordPress 7.1 or later

License

GPL-2.0-or-later