arraypress/wp-email-utils
Composer 安装命令:
composer require arraypress/wp-email-utils
包简介
A lightweight immutable value object for parsing and working with email addresses in WordPress.
README 文档
README
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
composer require arraypress/wp-email-utils
Usage
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
$domain = parse_email( $input )?->domain(); $tld = parse_email( $input )?->tld(); $valid = parse_email( $input )?->valid() ?? false;
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
$email = Email::parse( 'user@gmial.com' ); $email->has_typo(); // true $email->suggested_domain(); // 'gmail.com' $email->suggested_email(); // 'user@gmail.com'
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
| Pattern | Example | Matches |
|---|---|---|
| Full email | user@test.com |
Exact email match only |
| Domain | @company.com |
Any email ending with @company.com |
| TLD | .edu |
Any email ending with .edu |
| Partial domain | company.com |
@company.com and @sub.company.com |
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
$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
$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
// 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
Getters
| Method | Returns | Description |
|---|---|---|
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
| Method | Returns | Description |
|---|---|---|
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
| Method | Returns | Description |
|---|---|---|
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
| Method | Returns | Description |
|---|---|---|
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
| Method | Returns | Description |
|---|---|---|
equals() |
bool |
Exact match (case-insensitive) |
equals_base() |
bool |
Base address match (ignores tags) |
same_domain() |
bool |
Domain match |
Transformations
| Method | Returns | Description |
|---|---|---|
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
| Method | Returns | Description |
|---|---|---|
get_formatted() |
string |
local @ domain |
to_array() |
array |
Full parsed data |
Options
| Method | Returns | Description |
|---|---|---|
get_common_providers() |
array |
List of common providers |
get_role_prefixes() |
array |
List of role prefixes |
Requirements
- PHP 7.4+
- WordPress 5.0+
License
GPL-2.0-or-later
arraypress/wp-email-utils 适用场景与选型建议
arraypress/wp-email-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parser」 「email」 「wordpress」 「validation」 「subaddress」 「typo-detection」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arraypress/wp-email-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arraypress/wp-email-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arraypress/wp-email-utils 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
An MT940 bank statement parser for PHP
Laravel integration for the jsonapi.org parser
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-02-28