fedek6 / tld-mail-validator
PHP e-mail address validator using list of all known TLDs
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/fedek6/tld-mail-validator
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^9
README
PHP e-mail address validator using list of all known TLDs and simple domain MX record check. With ability to automatically update top-level domains list.
Usage example
use Fedek6\TldMailValidator\TldMailValidator; /** @var string $tldsFilePath */ $tldsFilePath = __DIR__ . '/../data/tlds-alpha-by-domain.txt'; /** @var array $addresses */ $addresses = require __DIR__ . '/addresses.php'; /** @var \Fedek6\TldMailValidator\TldMailValidator $validator */ $validator = new TldMailValidator($tldsFilePath); if ($validator->validate('janbrzechwa@mail.ru')) { echo 'This is email is OK. and has proper actual tld.'; } else { echo 'Something\'s wrong with this address'; }
If you want to test also MX record of a domain (slower), pass second argument to the constructor:
/** @var \Fedek6\TldMailValidator\TldMailValidator $validator */ $validator = new TldMailValidator($tldsFilePath, TldMailValidator::TEST_ALL);
Testing
composer test
Or:
./vendor/bin/phpunit --testdox --verbose --colors tests
Test one file
vendor/bin/phpunit --testdox --verbose --colors tests/RemoteFileUpdaterTest.php
Dry run before deploy
php -f examples/mx.php php -f examples/simple.php