2017 © Pedro Peláez
 

library assert-email

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

image

albertcolom/assert-email

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

  • Monday, December 4, 2017
  • by albertcolom
  • Repository
  • 1 Watchers
  • 0 Stars
  • 27 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 13 % Grown

The README.md

Assert email

Build Status Packagist License MIT, (*1)

PHP >= 5.4, (*2)

PHP library to check email inspired in webmozart/assert, (*3)

Installation

composer require albertcolom/assert-email

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

Valid

Check email valid RFC 2822, (*4)

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

Check temporary emails, it provides a built-in database of 2000+ domains, (*5)

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

Check DNS MX registry, (*6)

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

Check if domain allowed list, (*7)

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"

The Versions

04/12 2017

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0

 

The Development Requires

by Albert Colom

email assert check validate

04/12 2017

1.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0

 

The Development Requires

by Albert Colom

email assert check validate