PHPackages                             arraypress/wp-email-utils - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. arraypress/wp-email-utils

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arraypress/wp-email-utils
=========================

A lightweight immutable value object for parsing and working with email addresses in WordPress.

00PHP

Since Feb 28Pushed 2mo agoCompare

[ Source](https://github.com/arraypress/wp-email-utils)[ Packagist](https://packagist.org/packages/arraypress/wp-email-utils)[ RSS](/packages/arraypress-wp-email-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress Email Utils
=====================

[](#wordpress-email-utils)

A lightweight immutable value object for parsing and working with email addresses in WordPress. Extracts parts, detects subaddressing, identifies common providers, suggests typo corrections, and provides comparison utilities.

Installation
------------

[](#installation)

```
composer require arraypress/wp-email-utils
```

Usage
-----

[](#usage)

### Basic Parsing

[](#basic-parsing)

```
use ArrayPress\EmailUtils\Email;

$email = Email::parse( 'david+newsletter@gmail.com' );

if ( $email ) {
    $email->local();          // 'david+newsletter'
    $email->domain();         // 'gmail.com'
    $email->tld();            // 'com'
    $email->base_local();     // 'david'
    $email->base_address();   // 'david@gmail.com'
    $email->subaddress();     // 'newsletter'
}
```

### One-Liners

[](#one-liners)

```
$domain = parse_email( $input )?->domain();
$tld    = parse_email( $input )?->tld();
$valid  = parse_email( $input )?->valid() ?? false;
```

### Detection

[](#detection)

```
$email = Email::parse( 'admin@gmail.com' );

$email->is_subaddressed();        // false
$email->is_common_provider();     // true
$email->supports_subaddressing(); // true
$email->is_role_based();          // true
$email->has_mx();                 // true (DNS lookup)
```

### Typo Detection

[](#typo-detection)

```
$email = Email::parse( 'user@gmial.com' );

$email->has_typo();          // true
$email->suggested_domain();  // 'gmail.com'
$email->suggested_email();   // 'user@gmail.com'
```

### Pattern Matching

[](#pattern-matching)

```
$email = Email::parse( 'user@company.edu' );

// Match against a list of patterns
$email->matches_any( [ '.edu', '@company.com' ] );  // true
$email->matches_any( [ '.gov', '@test.com' ] );     // false

// Match a single pattern
$email->matches_pattern( '.edu' );          // true
$email->matches_pattern( '@company.edu' );  // true
$email->matches_pattern( 'company.edu' );   // true (partial domain)

// Match all patterns
$email->matches_all( [ '.edu', 'company.edu' ] );  // true

// Validate patterns (static)
Email::is_valid_pattern( '@domain.com' );  // true
Email::is_valid_pattern( '.edu' );         // true
Email::is_valid_pattern( 'invalid' );      // false

// Filter to valid patterns (static)
Email::filter_valid_patterns( [ '@test.com', '', '.edu', 'bad' ] );
// Returns: [ '@test.com', '.edu' ]

// Sanitize a pattern list from raw input (static)
Email::sanitize_pattern_list( "@test.com\n.edu\nbad\n" );
// Returns: [ '@test.com', '.edu' ]
```

#### Supported Pattern Types

[](#supported-pattern-types)

PatternExampleMatchesFull email`user@test.com`Exact email match onlyDomain`@company.com`Any email ending with @company.comTLD`.edu`Any email ending with .eduPartial domain`company.com`@company.com and @sub.company.com### Comparison

[](#comparison)

```
$email1 = Email::parse( 'david+test@gmail.com' );
$email2 = Email::parse( 'david+other@gmail.com' );

$email1->equals( $email2 );       // false
$email1->equals_base( $email2 );  // true (both are david@gmail.com)
$email1->same_domain( $email2 );  // true
```

### Transformations

[](#transformations)

```
$email = Email::parse( 'david@gmail.com' );

// Immutable - returns new instances
$email->with_subaddress( 'shopping' );  // david+shopping@gmail.com
$email->with_domain( 'yahoo.com' );     // david@yahoo.com
$email->with_local( 'john' );           // john@gmail.com
$email->without_subaddress();           // david@gmail.com
```

### Array Output

[](#array-output)

```
$email = Email::parse( 'david@gmail.com' );

$email->to_array();           // Full parsed data
echo json_encode( $email );   // JSON serializable
echo (string) $email;         // 'david@gmail.com'
```

### Options Helpers

[](#options-helpers)

```
// For building select dropdowns
Email::get_common_providers();                  // ['gmail.com' => 'gmail.com', ...]
Email::get_common_providers( as_options: true ); // [['value' => 'gmail.com', 'label' => 'gmail.com'], ...]

Email::get_role_prefixes();                     // ['admin' => 'admin', ...]
Email::get_role_prefixes( as_options: true );    // [['value' => 'admin', 'label' => 'admin'], ...]
```

Methods
-------

[](#methods)

### Getters

[](#getters)

MethodReturnsDescription`valid()``bool`Whether email is valid`original()``string`Original input string`normalized()``string`Lowercase, trimmed email`local()``string`Local part (before @)`domain()``string`Domain part (after @)`tld()``string`Top-level domain`base_local()``string`Local part without subaddress`base_address()``string`Email without subaddress`subaddress()``?string`Subaddress tag or null`digit_count()``int`Digits in local part### Detection

[](#detection-1)

MethodReturnsDescription`is_subaddressed()``bool`Contains + subaddress`is_common_provider()``bool`Gmail, Yahoo, Outlook, etc.`supports_subaddressing()``bool`Provider supports + addressing`is_role_based()``bool`admin@, info@, support@, etc.`has_mx()``bool`Has valid MX records (DNS check)### Typo Detection

[](#typo-detection-1)

MethodReturnsDescription`has_typo()``bool`Domain is a known typo`suggested_domain()``?string`Corrected domain or null`suggested_email()``?string`Full corrected email or null### Pattern Matching

[](#pattern-matching-1)

MethodReturnsDescription`matches_any()``bool`Matches any pattern in list`matches_all()``bool`Matches all patterns in list`matches_pattern()``bool`Matches a single pattern`is_valid_pattern()``bool`Pattern is valid (static)`filter_valid_patterns()``array`Filter to valid patterns (static)`sanitize_pattern_list()``array|string`Sanitize raw pattern input (static)### Comparison

[](#comparison-1)

MethodReturnsDescription`equals()``bool`Exact match (case-insensitive)`equals_base()``bool`Base address match (ignores tags)`same_domain()``bool`Domain match### Transformations

[](#transformations-1)

MethodReturnsDescription`with_local()``?static`New instance with different local`with_domain()``?static`New instance with different domain`with_subaddress()``?static`New instance with subaddress`without_subaddress()``?static`New instance without subaddress### Output

[](#output)

MethodReturnsDescription`get_formatted()``string``local @ domain``to_array()``array`Full parsed data### Options

[](#options)

MethodReturnsDescription`get_common_providers()``array`List of common providers`get_role_prefixes()``array`List of role prefixesRequirements
------------

[](#requirements)

- PHP 7.4+
- WordPress 5.0+

License
-------

[](#license)

GPL-2.0-or-later

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance56

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (2 commits)")

### Embed Badge

![Health badge](/badges/arraypress-wp-email-utils/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-wp-email-utils/health.svg)](https://phpackages.com/packages/arraypress-wp-email-utils)
```

###  Alternatives

[pelmered/fake-car

Fake-Car is a Faker provider that generates fake car data for you.

1271.2M2](/packages/pelmered-fake-car)

PHPackages © 2026

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