PHPackages                             mmucklo/email-parse - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. mmucklo/email-parse

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

mmucklo/email-parse
===================

email-parse a (reasonably) RFC822 / RF2822-compliant library for batch parsing multiple (and single) email addresses

2.8.0(3mo ago)46837.3k—3.8%14[1 PRs](https://github.com/mmucklo/email-parse/pulls)1MITPHPPHP ^8.1CI passing

Since Jul 8Pushed 3mo ago8 watchersCompare

[ Source](https://github.com/mmucklo/email-parse)[ Packagist](https://packagist.org/packages/mmucklo/email-parse)[ RSS](/packages/mmucklo-email-parse/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (25)Used By (1)

email-parse
===========

[](#email-parse)

[![Support on Patreon](https://camo.githubusercontent.com/ad2f9db89dbf03d0efcb9c1efbd9a815ef15d76004f5aeedd7f25cfc84c5d42b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50617472656f6e2d537570706f72742532304d652d6639363835343f6c6f676f3d70617472656f6e)](https://www.patreon.com/cw/MatthewJMucklo)

[![CI](https://github.com/mmucklo/email-parse/workflows/CI/badge.svg)](https://github.com/mmucklo/email-parse/actions)[![codecov](https://camo.githubusercontent.com/50a8868f8fa35ef3ecffae486442389587a177058fc91d47ecfd5ddee19e5727/68747470733a2f2f636f6465636f762e696f2f67682f6d6d75636b6c6f2f656d61696c2d70617273652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/mmucklo/email-parse)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e725de2a8997bea4e23731aaf1274e2b80561ea6e3621ca2275a746b075e6c09/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6d75636b6c6f2f656d61696c2d70617273652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mmucklo/email-parse/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/31950afee4fc77687029da4088058993772e98fa21d089c7ddfa723008925c43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6d75636b6c6f2f656d61696c2d70617273652e737667)](https://packagist.org/packages/mmucklo/email-parse)[![Total Downloads](https://camo.githubusercontent.com/66bc8d69f8b8e56a87f9eecd34d99bfa02c3538318130b23cd6e2f6c65906526/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6d75636b6c6f2f656d61696c2d70617273652e737667)](https://packagist.org/packages/mmucklo/email-parse)[![PHP Version](https://camo.githubusercontent.com/cc9cdea9aa96b40a822425e981b0a030e3371202973c7d57b74e8e99834f81dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c7565)](https://www.php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

Email\\Parse is a multiple (and single) batch email address parser that is reasonably RFC822 / RFC2822 compliant.

It parses a list of 1 to n email addresses separated by space, comma, or semicolon (configurable).

Installation:
-------------

[](#installation)

Add this line to your composer.json "require" section:

### composer.json

[](#composerjson)

```
    "require": {
       ...
       "mmucklo/email-parse": "*"
```

Usage:
------

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Email\Parse;

$result = Parse::getInstance()->parse("a@aaa.com b@bbb.com");
```

### Advanced Usage with ParseOptions

[](#advanced-usage-with-parseoptions)

You can configure separator behavior and other parsing options using `ParseOptions`:

```
use Email\Parse;
use Email\ParseOptions;

// Example 1: Use comma and semicolon as separators (default behavior includes whitespace)
$options = new ParseOptions([], [',', ';']);
$parser = new Parse(null, $options);
$result = $parser->parse("a@aaa.com; b@bbb.com, c@ccc.com");

// Example 2: Disable whitespace as separator (only comma and semicolon work)
$options = new ParseOptions([], [',', ';'], false);
$parser = new Parse(null, $options);
$result = $parser->parse("a@aaa.com; b@bbb.com"); // Works - uses semicolon
$result = $parser->parse("a@aaa.com b@bbb.com");  // Won't split - whitespace not a separator

// Example 3: Names with spaces always work regardless of whitespace separator setting
$options = new ParseOptions([], [',', ';'], false);
$parser = new Parse(null, $options);
$result = $parser->parse("John Doe , Jane Smith ");
// Returns 2 valid emails with names preserved
```

#### ParseOptions Constructor

[](#parseoptions-constructor)

```
/**
 * @param array $bannedChars Array of characters to ban from email addresses (e.g., ['%', '!'])
 * @param array $separators Array of separator characters (default: [','])
 * @param bool $useWhitespaceAsSeparator Whether to treat whitespace/newlines as separators (default: true)
 * @param LengthLimits|null $lengthLimits Email length limits. Uses RFC defaults if not provided
 */
public function __construct(
    array $bannedChars = [],
    array $separators = [','],
    bool $useWhitespaceAsSeparator = true,
    ?LengthLimits $lengthLimits = null
)
```

#### Configuring Length Limits

[](#configuring-length-limits)

You can customize RFC 5321 length limits using the `LengthLimits` class:

```
use Email\Parse;
use Email\ParseOptions;
use Email\LengthLimits;

// Use default RFC-compliant limits (64, 254, 63)
$options = new ParseOptions([], [','], true, LengthLimits::createDefault());

// Use relaxed limits for legacy systems (128, 512, 128)
$options = new ParseOptions([], [','], true, LengthLimits::createRelaxed());

// Custom limits
$limits = new LengthLimits(
    100,  // maxLocalPartLength (before @)
    300,  // maxTotalLength (entire email)
    100   // maxDomainLabelLength (each domain label)
);
$options = new ParseOptions([], [','], true, $limits);
$parser = new Parse(null, $options);
```

**Default RFC Limits:**

- Local part (before `@`): 64 octets (RFC 5321)
- Total email length: 254 octets (RFC erratum 1690)
- Domain label: 63 characters (RFC 1035)

#### Supported Separators

[](#supported-separators)

- **Comma (`,`)** - Configured via `$separators` parameter
- **Semicolon (`;`)** - Configured via `$separators` parameter
- **Whitespace (space, tab, newlines)** - Controlled by `$useWhitespaceAsSeparator` parameter
- **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.

#### Comment Extraction

[](#comment-extraction)

RFC 5322 allows comments in email addresses using parentheses. The parser automatically extracts these comments and returns them in the `comments` array:

```
use Email\Parse;

// Single comment
$result = Parse::getInstance()->parse('john@example.com (home address)', false);
// $result['comments'] = ['home address']

// Multiple comments
$result = Parse::getInstance()->parse('test(comment1)(comment2)@example.com', false);
// $result['comments'] = ['comment1', 'comment2']

// Nested comments
$result = Parse::getInstance()->parse('test@example.com (comment with (nested) parens)', false);
// $result['comments'] = ['comment with (nested) parens']

// No comments
$result = Parse::getInstance()->parse('test@example.com', false);
// $result['comments'] = []
```

Comments are stripped from the `address` field but preserved in `original_address`.

Notes:
======

[](#notes)

This should be RFC 2822 compliant, although it will let a few obsolete RFC 822 addresses through such as `test"test"test@xyz.com` (note the quoted string in the middle of the address, which may be obsolete as of RFC 2822). However it wont allow escaping outside of quotes such as `test@test@xyz.com`. This would have to be written as `"test@test"@xyz.com`

Here are a few other examples:

```
"John Q. Public"
this.is.an.address@xyz.com
how-about-an-ip@[10.0.10.2]
how-about-comments(this is a comment!!)@xyz.com

```

#### Function Spec

[](#function-spec)

```
/**
 * function parse($emails, $multiple = true, $encoding = 'UTF-8')
 * @param string $emails List of Email addresses separated by configured separators (comma, semicolon, whitespace by default)
 * @param bool $multiple (optional, default: true) Whether to parse for multiple email addresses or not
 * @param string $encoding (optional, default: 'UTF-8')The encoding if not 'UTF-8'
 * @return: see below: */

    if ($multiple):
         array('success' => boolean, // whether totally successful or not
               'reason' => string, // if unsuccessful, the reason why
               'email_addresses' =>
                    array('address' => string, // the full address (not including comments)
                        'original_address' => string, // the full address including comments
                        'simple_address' => string, // simply local_part@domain_part (e.g. someone@somewhere.com)
                         'name' => string, // the name on the email if given (e.g.: John Q. Public), including any quotes
                         'name_parsed' => string, // the name on the email if given (e.g.: John Q. Public), excluding any quotes
                        'local_part' => string, // the local part (before the '@' sign - e.g. johnpublic)
                        'local_part_parsed' => string, // the local part (before the '@' sign - e.g. johnpublic), excluding any quotes
                        'domain' => string, // the domain after the '@' if given
                         'ip' => string, // the IP after the '@' if given
                         'domain_part' => string, // either domain or IP depending on what given
                        'invalid' => boolean, // if the email is valid or not
                        'invalid_reason' => string, // if the email is invalid, the reason why
                        'comments' => array), // array of extracted comments (e.g. ['comment1', 'comment2'])
                    array( .... ) // the next email address matched
        )
    else:
        array('address' => string, // the full address (not including comments)
            'original_address' => string, // the full address including comments
            'simple_address' => string, // simply local_part@domain_part
            'name' => string, // the name on the email if given (e.g.: John Q. Public)
            'name_parsed' => string, // the name excluding quotes
            'local_part' => string, // the local part (before the '@' sign - e.g. johnpublic)
            'local_part_parsed' => string, // the local part excluding quotes
            'domain' => string, // the domain after the '@' if given
            'ip' => string, // the IP after the '@' if given
            'domain_part' => string, // either domain or IP depending on what given
            'invalid' => boolean, // if the email is valid or not
            'invalid_reason' => string, // if the email is invalid, the reason why
            'comments' => array) // array of extracted comments (e.g. ['comment1', 'comment2'])
    endif;
```

Other Examples:
---------------

[](#other-examples)

```
 $email = "\"J Doe\" ";
 $result = Email\Parse->getInstance()->parse($email, false);

 $result == array('address' => '"JD" ',
          'original_address' => '"JD" ',
          'simple_address' => 'johndoe@xyz.com',
          'name' => '"JD"',
          'name_parsed' => 'J Doe',
          'local_part' => 'johndoe',
          'local_part_parsed' => 'johndoe',
          'domain_part' => 'xyz.com',
          'domain' => 'xyz.com',
          'ip' => '',
          'invalid' => false,
          'invalid_reason' => '',
          'comments' => []);

 $emails = "testing@[10.0.10.45] testing@xyz.com, testing-"test...2"@xyz.com (comment)";
 $result = Email\Parse->getInstance()->parse($emails);
 $result == array(
            'success' => true,
            'reason' => null,
            'email_addresses' =>
                array(
                array(
                    'address' => 'testing@[10.0.10.45]',
                    'original_address' => 'testing@[10.0.10.45]',
                    'simple_address' => 'testing@[10.0.10.45]',
                    'name' => '',
                    'name_parsed' => '',
                    'local_part' => 'testing',
                    'local_part_parsed' => 'testing',
                    'domain_part' => '10.0.10.45',
                    'domain' => '',
                    'ip' => '10.0.10.45',
                    'invalid' => false,
                    'invalid_reason' => '',
                    'comments' => []),
                array(
                    'address' => 'testing@xyz.com',
                    'original_address' => 'testing@xyz.com',
                    'simple_address' => 'testing@xyz.com',
                    'name' => '',
                    'name_parsed' => '',
                    'local_part' => 'testing',
                    'local_part_parsed' => 'testing',
                    'domain_part' => 'xyz.com',
                    'domain' => 'xyz.com',
                    'ip' => '',
                    'invalid' => false,
                    'invalid_reason' => '',
                    'comments' => []),
                array(
                    'address' => '"testing-test...2"@xyz.com',
                    'original_address' => 'testing-"test...2"@xyz.com (comment)',
                    'simple_address' => 'testing-test...2@xyz.com',
                    'name' => '',
                    'name_parsed' => '',
                    'local_part' => '"testing-test...2"',
                    'local_part_parsed' => 'testing-test...2',
                    'domain_part' => 'xyz.com',
                    'domain' => 'xyz.com',
                    'ip' => '',
                    'invalid' => false,
                    'invalid_reason' => '',
                    'comments' => ['comment'])
                )
            );
```

###  Health Score

64

—

FairBetter than 99% of packages

Maintenance82

Actively maintained with recent releases

Popularity51

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 85.7% 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.

###  Release Activity

Cadence

Every ~184 days

Recently: every ~0 days

Total

22

Last Release

100d ago

Major Versions

0.4.3 → 1.0.02015-09-15

1.0.0 → 2.0.02017-04-15

PHP version history (6 changes)0.2.0PHP &gt;=5.4.0

2.0.0PHP &gt;=5.6.0

2.1.0PHP &gt;=7.1

2.3.0PHP ^8.2

2.5.0PHP ^8.1

2.2.x-devPHP ^7.1|^8.0

### Community

Maintainers

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

---

Top Contributors

[![mmucklo](https://avatars.githubusercontent.com/u/245122?v=4)](https://github.com/mmucklo "mmucklo (60 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (3 commits)")[![glensc](https://avatars.githubusercontent.com/u/199095?v=4)](https://github.com/glensc "glensc (2 commits)")[![mkraemer](https://avatars.githubusercontent.com/u/1070200?v=4)](https://github.com/mkraemer "mkraemer (2 commits)")[![ArthurHoaro](https://avatars.githubusercontent.com/u/1962678?v=4)](https://github.com/ArthurHoaro "ArthurHoaro (1 commits)")[![compwright](https://avatars.githubusercontent.com/u/138688?v=4)](https://github.com/compwright "compwright (1 commits)")[![arnested](https://avatars.githubusercontent.com/u/190005?v=4)](https://github.com/arnested "arnested (1 commits)")

---

Tags

emailparseRFC822RFC2822email-parsemultiple-emailbatch-email

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mmucklo-email-parse/health.svg)

```
[![Health](https://phpackages.com/badges/mmucklo-email-parse/health.svg)](https://phpackages.com/packages/mmucklo-email-parse)
```

###  Alternatives

[egulias/email-validator

A library for validating emails against several RFCs

11.6k691.3M307](/packages/egulias-email-validator)[zbateson/mail-mime-parser

MIME email message parser

54149.2M79](/packages/zbateson-mail-mime-parser)[voku/email-check

email-check (syntax, dns, trash, ...) library

504.1M4](/packages/voku-email-check)[omnimail/omnimail

PHP Library to send email across all platforms using one interface.

32934.3k](/packages/omnimail-omnimail)[vaibhavpandeyvpz/phemail

A pure PHP MIME parser for parsing raw email files (.eml) with full support for multipart messages, nested structures, and RFC 2046 compliance.

33121.7k1](/packages/vaibhavpandeyvpz-phemail)[thefox/smtpd

SMTP server (library) written in pure PHP.

1302.4k1](/packages/thefox-smtpd)

PHPackages © 2026

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