Skip to content
Email address value object.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/EmailAddress
tests
.gitattributes
.gitignore
.phpcs.xml.dist
.travis.yml
LICENSE.md
README.md
composer.json
phpstan.neon.dist
phpstan.tests.neon.dist

README.md

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

You can’t perform that action at this time.