rezozero / canonical-email
Simple PHP library to canonize emails address from gmail.com or other providers that allow several forms of email.
Installs: 33 492
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=7.2
- beberlei/assert: ^3.2
Requires (Dev)
- phpstan/phpstan: ^0.12.32
- phpunit/phpunit: ^8
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-10-25 18:48:58 UTC
README
Simple PHP library to canonize email addresses from gmail.com, outlook.com or other providers that allow several forms of email.
Be careful: do not store canonical email as primary email for login or sending emails!
Your users may not be able to login again to your site if they used a specific email syntax which differs from canonical. Only store canonical emails in order to test against duplicates and prevent new users from creating multiple accounts with same email using variants.
Always store email
and canonical_email
in your databases.
Strategies
LowercaseDomainStrategy
: for every emails, domain is case insensitive, so it should be lowercased.GmailStrategy
: for@gmail.com
addresses or whatever domain which MX servers are from Google GSuite (if$checkMxRecords
istrue
). This will remove any dots, and any character after+
sign. Then all email parts will be lowercased. When MX are checked, your app will use PHPgetmxrr
function.OutlookStrategy
: for@outlook.com
addresses. This will remove any character after+
sign.
Usage
composer require rezozero/canonical-email
use RZ\CanonicalEmail\EmailCanonizer; use RZ\CanonicalEmail\Strategy\GmailStrategy; use RZ\CanonicalEmail\Strategy\GSuiteStrategy; use RZ\CanonicalEmail\Strategy\LowercaseDomainStrategy; use RZ\CanonicalEmail\Strategy\OutlookStrategy; $canonizer = new EmailCanonizer([ new LowercaseDomainStrategy(), new GmailStrategy(), new GSuiteStrategy(), new OutlookStrategy() ]); $canonizer->getCanonicalEmailAddress($email);
Running tests
composer install
make test