PHPackages                             albertcolom/assert-email - 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. albertcolom/assert-email

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

albertcolom/assert-email
========================

PHP library check email (RFC 2822, DNS, Temporal Mail, Allowed Domains)

1.0(8y ago)1683[1 PRs](https://github.com/albertcolom/assert-email/pulls)MITPHPPHP ^5.4 || ^7.0

Since Dec 4Pushed 8y ago1 watchersCompare

[ Source](https://github.com/albertcolom/assert-email)[ Packagist](https://packagist.org/packages/albertcolom/assert-email)[ RSS](/packages/albertcolom-assert-email/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Assert email
============

[](#assert-email)

[![Build Status](https://camo.githubusercontent.com/4c1c08cec363209b37fd2a7477ef69c02416c9f63152fb07dffe711de57dd728/68747470733a2f2f7472617669732d63692e6f72672f616c62657274636f6c6f6d2f6173736572742d656d61696c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/albertcolom/assert-email)[![Packagist](https://camo.githubusercontent.com/d7e7f34aff344ac71d32783988c0c4ac7a7c41a6f2e214e9513c09be6c26d6ce/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c62657274636f6c6f6d2f6173736572742d656d61696c2e737667)](https://packagist.org/packages/albertcolom/assert-email)[![License MIT](https://camo.githubusercontent.com/74ea3d774c5103e6783dc09d57ef2525e1ddb80fee772cd83c2f766cf7e62e78/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/albertcolom/assert-email/blob/master/LICENSE)

PHP &gt;= 5.4

PHP library to check email inspired in [webmozart/assert](https://packagist.org/packages/webmozart/assert)

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

[](#installation)

```
composer require albertcolom/assert-email
```

Example usage
-------------

[](#example-usage)

```
use albertcolom\Assert\AssertEmail;

class User
{
    //...

    public function setEmail(string $email)
    {
        AssertEmail::valid($email);
    }
}
```

```
$user = new User;

$user->setEmail('foo@domain.com'); // true
$user->setEmail('foo@domain'); // InvalidArgumentException: Invalid email "foo@domain"
```

Assertions
----------

[](#assertions)

#### Valid

[](#valid)

Check email valid RFC 2822

```
valid($email, $message = '')

AssertEmail::valid('foo@domain.com'); // true
AssertEmail::valid('foo@domain'); // InvalidArgumentException: Invalid email "foo@domain"
AssertEmail::valid('foo@domain', 'Custom message %s'); // InvalidArgumentException: Custom message "foo@domain"
```

#### Temporal mail

[](#temporal-mail)

Check temporary emails, it provides a built-in database of [2000+](https://github.com/albertcolom/assert-email/blob/master/resources/temporal-mail-domain.txt) domains

```
temporalMail($email, $message = '')`

AssertEmail::temporalMail('foo@domain.com'); // true
AssertEmail::temporalMail('foo@yopmail.com'); // InvalidArgumentException: Temporal email is not allowed "foo@yopmail.com"
AssertEmail::temporalMail('foo@yopmail.com', 'Custom message %s'); // InvalidArgumentException: Custom message "foo@yopmail.com"
```

#### DNS

[](#dns)

Check DNS MX registry

```
dns($email, $message = '')

AssertEmail::dns('foo@domain.com'); // true
AssertEmail::dns('foo@domain.000'); // InvalidArgumentException: Incorrect domain name "domain.000"
AssertEmail::dns('foo@domain.000', 'Custom message %s'); // InvalidArgumentException: Custom message "domain.000"
```

#### Domains Allowed

[](#domains-allowed)

Check if domain allowed list

```
domainsAllowed($email, array $domains, $message = '')

$allowed = ['mysite.com', 'somedomain.xy', 'test.dev'];

AssertEmail::domainsAllowed('foo@test.dev', $allowed); // true
AssertEmail::domainsAllowed('foo@gmail.com', $allowed); // InvalidArgumentException: Domain is not allowed "foo@gmail.com"
AssertEmail::domainsAllowed('foo@gmail.com', $allowed, 'Custom message %s'); // InvalidArgumentException: Custom message "foo@gmail.com"
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

3085d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/674a680cd45448b58f9f62d7b44df0725f47b6195cabf92d57bc5c8dfb2dec09?d=identicon)[albertcolom](/maintainers/albertcolom)

---

Top Contributors

[![albertcolom](https://avatars.githubusercontent.com/u/8995654?v=4)](https://github.com/albertcolom "albertcolom (15 commits)")

---

Tags

assertcheckemailphprfc2822validatecheckemailassertvalidate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/albertcolom-assert-email/health.svg)

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[egulias/email-validator

A library for validating emails against several RFCs

11.6k691.3M307](/packages/egulias-email-validator)[sendgrid/sendgrid

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

1.5k47.5M164](/packages/sendgrid-sendgrid)[pelago/emogrifier

Converts CSS styles into inline style attributes in your HTML code

94944.1M110](/packages/pelago-emogrifier)[zbateson/mail-mime-parser

MIME email message parser

53949.2M79](/packages/zbateson-mail-mime-parser)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)

PHPackages © 2026

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