PHPackages                             yarri/email-address-recognizer - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. yarri/email-address-recognizer

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

yarri/email-address-recognizer
==============================

Parses and validates email addresses from To: or Cc: headers, including named addresses, quoted display names, and RFC 2822 groups.

v0.2(2mo ago)16051MITPHPPHP &gt;=5.6.0CI passing

Since Apr 16Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/yarri/EmailAddressRecognizer)[ Packagist](https://packagist.org/packages/yarri/email-address-recognizer)[ Docs](https://github.com/yarri/EmailAddressRecognizer)[ RSS](/packages/yarri-email-address-recognizer/feed)WikiDiscussions master Synced 3w ago

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

EmailAddressRecognizer
======================

[](#emailaddressrecognizer)

[![Tests](https://github.com/yarri/EmailAddressRecognizer/actions/workflows/tests.yml/badge.svg)](https://github.com/yarri/EmailAddressRecognizer/actions/workflows/tests.yml)

Parses email addresses from a `To:` or `Cc:` header value. Handles plain addresses, named addresses, quoted display names, and RFC 2822 group syntax. The result is iterable, countable, and accessible as an array.

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

[](#installation)

```
composer require yarri/email-address-recognizer

```

Basic Usage
-----------

[](#basic-usage)

```
$ear = new Yarri\EmailAddressRecognizer('John Doe , samantha@doe.com');

count($ear);        // 2
$ear->isValid();    // true
echo $ear;          // "John Doe , samantha@doe.com"

$ear[0]->getAddress();     // "john@doe.com"
$ear[0]->getName();        // "John Doe"
$ear[0]->getFullAddress(); // "John Doe "
$ear[0]->getDomain();      // "doe.com"
$ear[0]->isValid();        // true

$ear[1]->getAddress();     // "samantha@doe.com"
$ear[1]->getName();        // ""
$ear[1]->getFullAddress(); // "samantha@doe.com"
```

Supported Address Formats
-------------------------

[](#supported-address-formats)

```
// Plain address
new Yarri\EmailAddressRecognizer('john@doe.com');

// Named address
new Yarri\EmailAddressRecognizer('John Doe ');

// Quoted display name (allows commas and special characters in the name)
new Yarri\EmailAddressRecognizer('"Doe, John" ');

// Multiple addresses
new Yarri\EmailAddressRecognizer('john@doe.com, Jane Doe ');

// RFC 2822 group syntax
new Yarri\EmailAddressRecognizer('IT: John Doe , jane@doe.com;');

// Multiple groups
new Yarri\EmailAddressRecognizer('IT: John Doe , jane@doe.com; Management: boss@company.com, cto@company.com;');
```

Iterating Over Addresses
------------------------

[](#iterating-over-addresses)

`EmailAddressRecognizer` implements `Iterator`, `Countable`, and `ArrayAccess`:

```
$ear = new Yarri\EmailAddressRecognizer('john@doe.com, Jane Doe ');

foreach ($ear as $item) {
    echo $item->getAddress();  // "john@doe.com", then "jane@doe.com"
}

count($ear);  // 2
$ear[0];      // RecognizedItem for john@doe.com
```

Validation
----------

[](#validation)

`isValid()` returns `true` only when every parsed address is valid. Individual addresses can be checked separately:

```
$ear = new Yarri\EmailAddressRecognizer('john@doe.com, not-an-address');

$ear->isValid();       // false — at least one address is invalid

$ear[0]->isValid();    // true
$ear[1]->isValid();    // false
$ear[1]->getAddress(); // "" (empty for invalid addresses)
```

Input is normalized on output — extra whitespace is trimmed and trailing commas are dropped:

```
echo new Yarri\EmailAddressRecognizer('  john@doe.com ,  jane@doe.com  ');
// "john@doe.com, jane@doe.com"
```

RFC 2822 Groups
---------------

[](#rfc-2822-groups)

Group names are available via `getGroup()`:

```
$ear = new Yarri\EmailAddressRecognizer('IT: John Doe , jane@doe.com;');

$ear[0]->getGroup(); // "IT"
$ear[1]->getGroup(); // "IT"
```

RecognizedItem
--------------

[](#recognizeditem)

A single address string can be parsed directly using `RecognizedItem`:

```
$item = new Yarri\EmailAddressRecognizer\RecognizedItem('"Doe, John" ');

$item->isValid();        // true
$item->getAddress();     // "john@doe.com"
$item->getName();        // "Doe, John"
$item->getFullAddress(); // '"Doe, John" '
$item->getDomain();      // "doe.com"
$item->getGroup();       // ""
echo $item;              // '"Doe, John" '
```

`RecognizedItem` is invalid if the input contains zero or more than one address:

```
(new Yarri\EmailAddressRecognizer\RecognizedItem(''))->isValid();                             // false
(new Yarri\EmailAddressRecognizer\RecognizedItem('john@doe.com, jane@doe.com'))->isValid();   // false
```

Testing
-------

[](#testing)

```
composer install --dev
cd test
../vendor/bin/run_unit_tests

```

License
-------

[](#license)

EmailAddressRecognizer is free software distributed [under the terms of the MIT license](http://www.opensource.org/licenses/mit-license)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance87

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity37

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.

###  Release Activity

Cadence

Every ~366 days

Total

5

Last Release

66d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/974278?v=4)[Jaromir Tomek](/maintainers/yarri)[@yarri](https://github.com/yarri)

---

Top Contributors

[![yarri](https://avatars.githubusercontent.com/u/974278?v=4)](https://github.com/yarri "yarri (50 commits)")

### Embed Badge

![Health badge](/badges/yarri-email-address-recognizer/health.svg)

```
[![Health](https://phpackages.com/badges/yarri-email-address-recognizer/health.svg)](https://phpackages.com/packages/yarri-email-address-recognizer)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[json-mapper/laravel-package

The JsonMapper package for Laravel

25188.9k3](/packages/json-mapper-laravel-package)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

112.9k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

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