black/email
PHP 5.4+ value object for safer email handling. Validates email format (throws on invalid), exposes recipient/domain/tld getters, array parsing, and equality checks. Note: relies on FILTER_VALIDATE_EMAIL; limited for non-ASCII and provider rules.
PHP 5.4+ library to make working with Email safer, easier, and fun!
The recommended way to install Email is through Composer:
{
"require": {
"black/email": "@stable"
}
}
Protip: You should browse the black/email page to choose a stable version to use, avoid the @stable meta
constraint.
Usage is simple. Just create a new EmailEmail, if your email is invalid an Email\Exception\InvalidEmailEmailException
will be thrown. Be aware of this, the validation is on the format, not on a A or MX record in a valid DNS.
$email = new Email\EmailEmail("foo@bar.com");
$email->getValue(); // return foot@bar.com
$email->getValueAsArray() // return ['recipient' => "foo", 'domain' => "bar", 'tld' => "com"]
List of available getters
getValue()getValueAsArray()getRecipient()getDomain()getTld()Check if two email are equals
isEqualTo(Email\EmailEmail $email): Check if two emails are equals
WARNING
FILTER_VALIDATE_EMAIL will not works with non-standard ASCII characters so an email like this
me@domain.中国 will throw an InvalidEmailAddressException.
FILTER_VALIDATE_EMAIL don't know rules of providers. 0me@hotmail.com is invalid for hotmail but valid for PHP.
Email is released under the MIT License. See the bundled LICENSE file for details.
See CONTRIBUTING file.
This README is heavily inspired by Geocoder library by the great @willdurand. This guy needs your PR for the sake of the REST in PHP.
Alexandre "pocky" Balmes alexandre@lablackroom.com. Send me Flattrs if you love my work, buy me gift or hire me!
How can I help you explore Laravel packages today?