rezozero / canonical-email
Simple PHP library to canonize emails address from gmail.com or other providers that allow several forms of email.
Installs: 35 057
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=7.4
- beberlei/assert: ^3.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^1.12.12
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-12-02 20:32:39 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 email, 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