Download the PHP package mmucklo/email-parse without Composer
On this page you can find all versions of the php package mmucklo/email-parse. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mmucklo/email-parse
More information about mmucklo/email-parse
Files in mmucklo/email-parse
Package email-parse
Short Description RFC 5322 / RFC 6531-compliant library for batch parsing multiple (and single) email addresses
License MIT
Informations about the package email-parse
email-parse
Email\Parse is a batch email address parser with configurable RFC compliance levels (RFC 5322, RFC 6531/6532, RFC 2822). Supports internationalized email addresses (UTF-8 local parts and IDN domains).
It parses a list of 1 to n email addresses separated by comma and whitespace by default, with configurable separators (e.g. semicolon).
Other docs: ROADMAP
Installation:
Usage:
Basic Usage
Advanced Usage with ParseOptions
You can configure separator behavior and other parsing options using ParseOptions:
RFC Compliance Presets
The parser provides factory methods on ParseOptions for common RFC compliance levels:
Preset Comparison:
| Preset | Standard | UTF-8 Support | Obsolete Syntax | Use Case |
|---|---|---|---|---|
rfc6531() |
RFC 6531/6532 | Full (NFC normalization) | No | International apps with UTF-8 emails |
rfc5321() |
RFC 5321 | ASCII only | No | Modern ASCII-only SMTP validation |
rfc5322() |
RFC 5322 + obsolete | ASCII only | Yes | Recommended default (v3.0+) |
rfc2822() |
RFC 2822 | ASCII only | Yes | Legacy system integration |
new ParseOptions() |
Legacy | Permissive | No | v2.x backward-compatible default |
RFC 6531 Features (rfc6531()):
- UTF-8 characters in local-part and domain (e.g.,
日本語@example.jp) - Unicode normalization (NFC per RFC 6532 §3.1)
- C0/C1 control character rejection (RFC 6530 §10.1)
- Internationalized domains (IDN) with punycode output (
includeDomainAscii = true) - Length limits in octets (multi-byte UTF-8 counts as multiple octets)
- Requires PHP Intl extension for full functionality
Example:
Customizing Rules
Each preset sets a combination of boolean rule properties. Rule properties are readonly (v3.1+) — override them via fluent withX() builders that return new instances:
Available Rule Properties:
| Property | Default | Description |
|---|---|---|
| Local-Part Rules | ||
allowUtf8LocalPart |
true |
Allow UTF-8 characters in local-part (RFC 6531) |
allowObsLocalPart |
false |
Allow obsolete syntax: leading/trailing/consecutive dots (RFC 5322 §4.4) |
allowQuotedString |
true |
Allow quoted-string form in local-part |
validateQuotedContent |
false |
Validate qtext/quoted-pair rules in quoted strings |
rejectEmptyQuotedLocalPart |
false |
Reject ""@domain (RFC 5321 EID 5414) |
| Domain Rules | ||
allowUtf8Domain |
true |
Allow Unicode (U-label) domain names (RFC 5890/5891) |
allowDomainLiteral |
true |
Allow address-literal form [IP] or [IPv6:addr] in domain (RFC 5321 §4.1.3) |
requireFqdn |
false |
Require at least two domain labels (RFC 5321 §2.3.5) |
validateIpGlobalRange |
true |
Validate IP addresses are in global range |
| Character Validation | ||
rejectC0Controls |
false |
Reject C0 control characters U+0000-U+001F (RFC 5321) |
rejectC1Controls |
false |
Reject C1 control characters U+0080-U+009F (RFC 6530) |
applyNfcNormalization |
false |
Apply NFC Unicode normalization (RFC 6532 §3.1) |
validateDisplayNamePhrase |
false |
Enforce RFC 5322 §3.2.5 phrase syntax on unquoted display names |
strictIdna |
false |
Apply full IDNA2008 conformance on U-label domains (RFC 5891/5892/5893) |
allowObsRoute |
false |
Accept RFC 5322 §4.4 obs-route source-routes like <@host1,@host2:user@host3> |
localPartNormalizer |
null |
?callable(string $local, string $domain): string — domain-specific canonicalization hook (v3.3+); set via withLocalPartNormalizer() |
| Length & Output | ||
enforceLengthLimits |
true |
Enforce RFC 5321 length limits (64/254/63) |
includeDomainAscii |
false |
Include punycode domain_ascii in output |
The defaults shown above are for new ParseOptions() (legacy). Each factory method sets its own combination — see the source code for exact values.
ParseOptions Constructor
Configuring Length Limits
You can customize RFC 5321 length limits using the LengthLimits class:
Default RFC Limits:
- Local part (before
@): 64 octets (RFC 5321) - Total email length: 254 octets (RFC 3696 EID 1690)
- Domain label: 63 octets (RFC 1035)
Supported Separators
- Comma (
,) - Configured via$separatorsparameter - Semicolon (
;) - Configured via$separatorsparameter - Whitespace (space, tab, newlines) - Controlled by
$useWhitespaceAsSeparatorparameter - Mixed separators - All configured separators work together seamlessly
Note: When useWhitespaceAsSeparator is false, whitespace is still properly cleaned up and names with spaces (like "John Doe") continue to work correctly.
Internationalized Domains (IDN)
The parser supports internationalized domain names per RFC 5890/5891. Unicode domains are normalized to ASCII (punycode) for validation and length enforcement, while the original Unicode domain is preserved.
The domain_ascii field is included in the output when includeDomainAscii is true on the ParseOptions instance. This is enabled by default in the rfc6531() preset.
Comment Extraction
RFC 5322 allows comments in email addresses using parentheses. The parser automatically extracts these comments and returns them in the comments array:
Comments are stripped from the address field but preserved in original_address.
Migration Guide
Migrating from v2.x to v3.0:
See UPGRADE.md for the complete list of breaking changes, deprecations, and bug-fix behavior changes.
Quick start:
Key differences between legacy and rfc5322():
rfc5322()rejects C0 control characters (rejectC0Controls = true)rfc5322()allows obsolete local-part syntax (consecutive dots, etc.)rfc5322()enforces RFC 5321 length limits- Legacy mode (
new ParseOptions()) accepts UTF-8 by default;rfc5322()does not
Adding UTF-8 support:
Function Spec
Other Examples:
The following examples use the legacy array-returning parse() method to document its full output shape. New code should prefer parseSingle() / parseMultiple() (see Basic Usage) for typed return values; both APIs expose the same underlying fields.
All versions of email-parse with dependencies
ext-mbstring Version *
psr/log Version ^3.0
symfony/polyfill-intl-idn Version ^1.31
