black/email

A simple email value object for your projects

v1.2 2016-10-07 15:57 UTC

This package is auto-updated.

Last update: 2024-11-29 04:57:36 UTC


README

PHP 5.4+ library to make working with Email safer, easier, and fun!

SensioLabsInsight Build Status Scrutinizer Quality Score Latest Stable Version Total Downloads

Installation

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

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.

License

Email is released under the MIT License. See the bundled LICENSE file for details.

Contributing

See CONTRIBUTING file.

Credits

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!