When you open up my script folder, you’ll see the following files and directories:
The file & folders
- inc: Contains the common files, where all the logic live here.
- index.php: A simple form with Bootstrap style for verifing email exist or not.
- cli.php: A simple file allow you verify email in command line directly.
How to install
Add this class to your file:
That's all, now you are ready to use that class!
How to use
Initialize the class:
$ev = new EmailVerification(‘[email protected]', [email protected]');
Or you can specify other port number to check than 25:
$ev = new EmailVerification(‘[email protected]', [email protected]', 465);
You can also modify/set the values of email to verify, verifier email, and port number on the fly after initializing:
$ev->setEmail('<another email Address to verify>');
$ev->setVerifierEmail('<another verifier email>');
Then you call the verify function: $ev->verify();
This will return an array:
'email' => '[email protected]',
'format_valid' => true,
'mx_found' => true,
'smtp_check' => true,
'catch_all' => true,
'role' => false,
'disposable' => false
- email: this field contain the value of checking email
- format_valid: this field indicate that email has valid syntax or not.
- mx_found: this field indicate that email has MX records or not.
- smtp_check: this field indicate that email actual exist or not.
- catch_all: this field indicate that email server of checking email has setup catch all or not.
- role: this field indicate that email is role-based or not.
- disposable: this field indicate that email is using disposable email service or not.
If you want to get all debug messages while checking email, call this function: $ev->getDebugInfo(); which will return an array:
0 => 'Initialized with values: email = [email protected], verifier email = [email protected], port = 25',
1 => 'Email was set to [email protected]',
2 => 'Verifier email was set to [email protected]',
3 => 'Port was set to 25',
4 => 'Verify function was called.',
5 => 'Finding MX record...',
6 => 'No MX record was found.',
There are two examples of this script that you can run:
1. Command line: just simple open a terminal and type:
php cli.php -e <the email to be checked> -v <the email to be provided to server> -p <port number>
php cli.php --email <the email to be checked> --verifier-email <the email to be provided to server> --port <port number>
-e, --email: is the email that you want to check
-v, --verifier-email: is an email address to be provided to the server. This email needs to be valid and from the same server that the script is running from.
-p, --port: is the SMTP port to check
2. Via web browser: Open your favorite browser and enter the path to index.php, example: http://localhost/verify-email then enter needed information to check
- Some mail servers will reject the test message to prevent spammers from checking against their users' emails and filter the valid emails, so this script might not work properly with all mail servers
- You server should be configured properly as a mail server to avoid being blocked or blacklisted