nepada/email-address

Email address value object.

v2.2.0 2019-12-23 11:43 UTC

This package is auto-updated.

Last update: 2020-03-28 17:50:17 UTC


README

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