Statistics
1092
3
0
47d
Badges
Tags
mail
Dependencies

Email address value object

Build Status Coverage Status Downloads this Month Latest stable

Installation

Via Composer:

$ composer require nepada/email-address

Usage

Creating value object

$emailAddress = Nepada\EmailAddress\EmailAddress::fromString('Real.example+suffix@HÁČKYčárky.cz');
$emailAddress = Nepada\EmailAddress\EmailAddress::fromDomainAndLocalPart('HÁČKYčárky.cz', 'Real.example+suffix');

Nepada\EmailAddress\InvalidEmailAddressException is thrown in case of invalid input value.

Converting back to string

echo((string) $emailAddress); // Real.example+suffix@HÁČKYčárky.cz
echo($emailAddress->toString()); // Real.example+suffix@HÁČKYčárky.cz
echo($emailAddress->getOriginalValue()); // Real.example+suffix@HÁČKYčárky.cz

Email address with normalized domain part

echo($emailAddress->getValue()); // Real.example+suffix@xn--hkyrky-ptac70bc.cz

Whole email address normalized and lowercased

echo($emailAddress->getLowercaseValue()); // real.example+suffix@xn--hkyrky-ptac70bc.cz

Note: This is not RFC 5321 compliant, however in practice all major mail providers treat local part in case insensitive manner.

Getting local and domain part separately

echo($emailAddress->getLocalPart()); // Real.example+suffix
echo($emailAddress->getDomain()); // xn--hkyrky-ptac70bc.cz

Integrations

  • v2.0.0 2.0.0

    • Added EmailAddress::toString() method
    • Constructor is private, use static factories EmailAddress::fromString() and EmailAddress::fromDomainAndLocalPart() instead (BC break)
    • EmailAddress is final (possible BC break)
  • v1.1.0 1.1.0

    • Throw exception if domain normalization fails (possible BC break).
    • Explicitly require ext-intl.
  • v1.0.0 1.0.0

    • Initial release.

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com