This package allows you to validate an email before actually sending mail to that email. Checking MX records occurs, including with the help of google.
- PHP 8.1.5+
- Composer 2+
composer require ashvedov/email-validator
Anywhere in your code, just include the class EmailValidator in the use section and you're good to go. It is possible to receive the result of the check as JSON, array or string.
use Src\EmailValidator;
$validator = new EmailValidator(
emails: [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
23,
'[email protected]'
]
);
var_dump($validator->validate()->toArray());
- array:
array(3) {
[23]=>
array(4) {
[0]=>
string(17) "filter_var_errors"
[1]=>
string(12) "regex_errors"
[2]=>
string(16) "mx_record_errors"
[3]=>
string(22) "world_mx_record_errors"
}
["[email protected]"]=>
array(2) {
[0]=>
string(16) "mx_record_errors"
[1]=>
string(22) "world_mx_record_errors"
}
["[email protected]"]=>
array(2) {
[0]=>
string(16) "mx_record_errors"
[1]=>
string(22) "world_mx_record_errors"
}
}
- JSON:
{"23":["filter_var_errors","regex_errors","mx_record_errors","world_mx_record_errors"],"[email protected]":["mx_record_errors","world_mx_record_errors"],"[email protected]":["mx_record_errors","world_mx_record_errors"]}
- String:
email [23] not valid, email [[email protected]] not valid, email [[email protected]] not valid