PHPackages                             nordic/email-address - 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. nordic/email-address

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

nordic/email-address
====================

Immutable Email Address value object

1.0.0(7y ago)0231MITPHPPHP ~7.1

Since May 1Pushed 7y ago1 watchersCompare

[ Source](https://github.com/nordic-alliance/email-address)[ Packagist](https://packagist.org/packages/nordic/email-address)[ Docs](https://github.com/nordic-alliance/email-address)[ RSS](/packages/nordic-email-address/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (3)Used By (1)

Email Address immutable value object
====================================

[](#email-address-immutable-value-object)

[![PHP version](https://camo.githubusercontent.com/9b4e67ca5f9446de7b3183704b4dba7929f473dd931c8de30b84005cde91ec4c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068702d762f6e6f726469632d616c6c69616e63652f656d61696c2d616464726573732e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/9b4e67ca5f9446de7b3183704b4dba7929f473dd931c8de30b84005cde91ec4c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068702d762f6e6f726469632d616c6c69616e63652f656d61696c2d616464726573732e7376673f7374796c653d666c61742d737175617265)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/49610338240c7966fffba4631a321b41daaedccb72a45f6d4d33a6543bb88225/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6e6f726469632d616c6c69616e63652f656d61696c2d616464726573732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/nordic-alliance/email-address)[![Coverage Status](https://camo.githubusercontent.com/e96e29e536f6422b18746b060f8dd03dca0e3dd6c8697ee15b4a6fb33975e0d5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6e6f726469632d616c6c69616e63652f656d61696c2d616464726573732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/nordic-alliance/email-address/code-structure)[![Quality Score](https://camo.githubusercontent.com/e00409ac357fa50d04cdbe7218a1ecae3c74b327b066ef238c4eaf428548f6bf/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6e6f726469632d616c6c69616e63652f656d61696c2d616464726573732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/nordic-alliance/email-address)

This package represents an immutable email address value object and additional utility classes.

Install
-------

[](#install)

Via Composer

```
$ composer require nordic/email-address
```

Features
--------

[](#features)

- Immutable value object
- No dependencies
- Include null email address value object (see [Null object pattern](https://en.wikipedia.org/wiki/Null_object_pattern))
- Include assertion class
- Include factory class

Basic classes and interfaces
----------------------------

[](#basic-classes-and-interfaces)

`EmailAddressInterface` - is the base interface for email address value objects.

`EmailAddress` - immutable email address value object that will be used most of the time.

`NullEmailAddress` - null email address value object (null object design pattern).

Usage
-----

[](#usage)

```
use Nordic\EmailAddress\EmailAddress;
use Nordic\EmailAddress\NullEmailAddress;

$emailAddress = new EmailAddress('email@example.com');
$nullEmailAddress = new NullEmailAddress;

// Compare two email addresses
$emailAddressSame = new EmailAddress('email@example.com');
$emailAddressAnother = new EmailAddress('another@example.com');

var_dump($emailAddress->equals($emailAddressSame)); // boolean(true)
var_dump($emailAddress->equals($emailAddressAnother)); // boolean(false)
```

### Exceptions

[](#exceptions)

`InvalidEmailAddressException` - is a basic exception that you can use. The first argument is a string value.

```
use Nordic\EmailAddress\InvalidEmailAddressException;

$e = new InvalidEmailAddressException('wrong_email', 'Wrong email address');
var_dump($e->getEmailAddress()); // string(17) "wrong_email"
```

### Factory pattern

[](#factory-pattern)

`EmailAddressFactoryInterface` - is the base interface for email address factory.

`EmailAddressFactory` - is the factory class that creates `EmailAddress` value objects.

```
use Nordic\EmailAddress\EmailAddressFactory;

$factory = new EmailAddressFactory;
$emailAddress = $factory->createEmailAddress('email@example.com');
$nullEmailAddress = $factory->createEmailAddress();
$emailAddress = $factory->createEmailAddress('wrong_email'); // will throw InvalidEmailAddressException
```

### Assertion

[](#assertion)

The class `Assertion` can be used for checking if string value is an email address string or check if email address value object is not null object. All methods will throw `InvalidEmailAddressException` if assertion will fails. You can always set a custom exception message as the second method argument.

Available methods:

- `Assertion::email` - will fail in case if string value is not a valid email address.
- `Assertion::notNull` - will fail in case if email address value object is null email address object.

```
use Nordic\EmailAddress\Assertion;

$email = Assertion::email('email@example.com');
$email = Assertion::email('wrong_email'); // will throw InvalidEmailAddressException

$emailAddress = Assertion::notNull($emailAddress);
// will throw InvalidEmailAddressException if $emailAddress is instance of NullEmailAddress
```

### Additional helpers

[](#additional-helpers)

#### Provider interface and trait

[](#provider-interface-and-trait)

Use interface `EmailAddressProviderInterface` and trait `EmailAddressProviderTrait` when the object should only provide email address value object (see [EmailAddressProviderTest.php](tests/EmailAddressProviderTest.php) for examples).

#### Aware intrerface and trait

[](#aware-intrerface-and-trait)

Use interface `EmailAddressAwareInterface` and trait `EmailAddressAwareTrait` when the object should aware about email address value object (see [EmailAddressAwareTest.php](tests/EmailAddressAwareTest.php) for examples).

Example
-------

[](#example)

```
use Nordic\EmailAddress\Assertion;
use Nordic\EmailAddress\EmailAddress;
use Nordic\EmailAddress\EmailAddressInterface;
use Nordic\EmailAddress\EmailAddressFactory;
use Nordic\EmailAddress\InvalidEmailAddressException;
use Nordic\EmailAddress\EmailAddressProviderInterface;
use Nordic\EmailAddress\EmailAddressProviderTrait;

class MyClass implements EmailAddressProviderInterface
{
    use EmailAddressProviderTrait;

    public function __construct(EmailAddressInterface $emailAddress)
    {
        $this->emailAddress = Assertion::notNull($emailAddress);
    }
}

$factory = new EmailAddressFactory;

try {
    $myClass = new MyClass($factory->createEmailAddress('email@example.com'));
} catch (InvalidEmailAddressException $e) {
    // do something
}

$emailAddress = $myClass->getEmailAddress();
```

Testing
-------

[](#testing)

```
$ composer test
```

Credits
-------

[](#credits)

- [Serhii Diahovchenko](https://github.com/DyaGa)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

2616d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/408ccdb79821767c6cb2cea53f99d5d8422460fdb376198f9107204a43b7c6b9?d=identicon)[DyaGa](/maintainers/DyaGa)

---

Top Contributors

[![Serhii-DV](https://avatars.githubusercontent.com/u/101594?v=4)](https://github.com/Serhii-DV "Serhii-DV (28 commits)")

---

Tags

emailemail-addressimmutablephpphp7value-objectValue Objectemailimmutableemail addressnordic

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[egulias/email-validator

A library for validating emails against several RFCs

11.6k719.7M402](/packages/egulias-email-validator)[sendgrid/sendgrid

This library allows you to quickly and easily send emails through Twilio SendGrid using PHP.

1.5k49.8M183](/packages/sendgrid-sendgrid)[pelago/emogrifier

Converts CSS styles into inline style attributes in your HTML code

94745.9M132](/packages/pelago-emogrifier)[zbateson/mail-mime-parser

MIME email message parser

54651.9M86](/packages/zbateson-mail-mime-parser)[soundasleep/html2text

A PHP script to convert HTML into a plain text format

48020.6M85](/packages/soundasleep-html2text)[opcodesio/mail-parser

Parse emails without the mailparse extension

228.1M9](/packages/opcodesio-mail-parser)

PHPackages © 2026

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