Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fedek6/tld-mail-validator
PHP e-mail address validator using list of all known TLDs
https://github.com/fedek6/tld-mail-validator
mail mail-validation php tld validator
Last synced: about 2 months ago
JSON representation
PHP e-mail address validator using list of all known TLDs
- Host: GitHub
- URL: https://github.com/fedek6/tld-mail-validator
- Owner: fedek6
- License: apache-2.0
- Created: 2021-03-16T09:14:50.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-08T10:24:56.000Z (over 3 years ago)
- Last Synced: 2024-04-10T04:11:13.653Z (9 months ago)
- Topics: mail, mail-validation, php, tld, validator
- Language: PHP
- Homepage:
- Size: 44.9 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# TLD e-mail validator
[![Build Status](https://travis-ci.com/fedek6/tld-mail-validator.svg?token=Fpapy2MXqrwtfsLgfThp&branch=main)](https://travis-ci.com/fedek6/tld-mail-validator)
PHP e-mail address validator using list of all known [TLDs](https://data.iana.org/TLD/tlds-alpha-by-domain.txt) and simple domain MX record check. With ability to automatically update top-level domains list.
## Usage example
```php
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('[email protected]')) {
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:
```php
/** @var \Fedek6\TldMailValidator\TldMailValidator $validator */
$validator = new TldMailValidator($tldsFilePath, TldMailValidator::TEST_ALL);
```## Testing
```bash
composer test
```Or:
```bash
./vendor/bin/phpunit --testdox --verbose --colors tests
```### Test one file
```bash
vendor/bin/phpunit --testdox --verbose --colors tests/RemoteFileUpdaterTest.php
```### Dry run before deploy
```bash
php -f examples/mx.php
php -f examples/simple.php
```