Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/albertcolom/assert-email
PHP library check email (RFC 2822, DNS, Temporal Mail, Allowed Domains)
https://github.com/albertcolom/assert-email
assert check email php rfc2822 validate
Last synced: about 1 month ago
JSON representation
PHP library check email (RFC 2822, DNS, Temporal Mail, Allowed Domains)
- Host: GitHub
- URL: https://github.com/albertcolom/assert-email
- Owner: albertcolom
- License: mit
- Created: 2017-12-01T12:07:30.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-18T09:51:36.000Z (over 6 years ago)
- Last Synced: 2024-11-24T09:31:40.805Z (about 1 month ago)
- Topics: assert, check, email, php, rfc2822, validate
- Language: PHP
- Homepage: https://packagist.org/packages/albertcolom/assert-email
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Assert email
==============
[![Build Status](https://travis-ci.org/albertcolom/assert-email.svg?branch=master)](https://travis-ci.org/albertcolom/assert-email)
[![Packagist](http://img.shields.io/packagist/v/albertcolom/assert-email.svg)](https://packagist.org/packages/albertcolom/assert-email)
[![License MIT](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/albertcolom/assert-email/blob/master/LICENSE)PHP >= 5.4
PHP library to check email inspired in [webmozart/assert](https://packagist.org/packages/webmozart/assert)
## Installation
```php
composer require albertcolom/assert-email```
## Example usage
```php
use albertcolom\Assert\AssertEmail;class User
{
//...
public function setEmail(string $email)
{
AssertEmail::valid($email);
}
}```
```php
$user = new User;
$user->setEmail('[email protected]'); // true
$user->setEmail('foo@domain'); // InvalidArgumentException: Invalid email "foo@domain"
```## Assertions
#### Valid
Check email valid RFC 2822
```php
valid($email, $message = '')AssertEmail::valid('[email protected]'); // true
AssertEmail::valid('foo@domain'); // InvalidArgumentException: Invalid email "foo@domain"
AssertEmail::valid('foo@domain', 'Custom message %s'); // InvalidArgumentException: Custom message "foo@domain"
```#### 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
```php
temporalMail($email, $message = '')`AssertEmail::temporalMail('[email protected]'); // true
AssertEmail::temporalMail('[email protected]'); // InvalidArgumentException: Temporal email is not allowed "[email protected]"
AssertEmail::temporalMail('[email protected]', 'Custom message %s'); // InvalidArgumentException: Custom message "[email protected]"
```#### DNS
Check DNS MX registry
```php
dns($email, $message = '')AssertEmail::dns('[email protected]'); // true
AssertEmail::dns('[email protected]'); // InvalidArgumentException: Incorrect domain name "domain.000"
AssertEmail::dns('[email protected]', 'Custom message %s'); // InvalidArgumentException: Custom message "domain.000"
```#### Domains Allowed
Check if domain allowed list
```php
domainsAllowed($email, array $domains, $message = '')$allowed = ['mysite.com', 'somedomain.xy', 'test.dev'];
AssertEmail::domainsAllowed('[email protected]', $allowed); // true
AssertEmail::domainsAllowed('[email protected]', $allowed); // InvalidArgumentException: Domain is not allowed "[email protected]"
AssertEmail::domainsAllowed('[email protected]', $allowed, 'Custom message %s'); // InvalidArgumentException: Custom message "[email protected]"
```