Do you want to write a real-time email verifier script in PHP? A real email address means an email that actually exists. This email address is not a fake one. In this article, I show you how to write an email verifier script using Kickbox in PHP.
Why We Need to Check If Email Exists?
If you are running a membership site, then a user can register to your system by using a fake email address. Of course, we use the flow of an activation link before the user gets access to the system. But, it does not stop users from registering. Your database will have tons of useless records with these throw-away email addresses.
Another reason is email bouncing. While sending emails to invalid email addresses, you will face the problem of email bouncing as these emails do not really exist.
To avoid such problems, we should add an email verifier before users register to our application.
Kickbox provides an email verification service that helps to check if the email is valid or not. This service would act as a real-time email checker for our application.
Get Kickbox API Key
For implementing this library, you need to first create an account on Kickbox. Keep a note Kickbox offers 100 free email verifications. Check out their pricing page for additional quotas.
Once you created an account with Kickbox, login to your account, go to Account Settings->API Keys, and create API Key.
After creating the API key, you can view it by clicking on the eye icon next to the API Key field.
Email Verifier Script in PHP
As said we are going to write an email verifier script in PHP. Kickbox provides its official library for PHP. To install the Kickbox library, open the terminal in your project root directory and run the below command.
composer require kickbox/kickbox
Upon library installation, we are good to go ahead and write the actual code that checks if the email really exists.
<?php
require_once "vendor/autoload.php";
$client = new Kickbox\Client('Kickbox_API_KEY');
$kickbox = $client->kickbox();
try {
$response = $kickbox->verify("EMAIL_ADDRESS");
pr($response);
switch($response->code) {
case 200:
if ($response->body['result'] == 'deliverable') {
echo "Valid Email.";
} else {
echo "Invalid Email.";
}
break;
case 429:
echo "Rate limit exceeded.";
break;
default:
echo "Something went wrong";
}
}
catch (Exception $e) {
echo "Code: " . $e->getCode() . " Message: " . $e->getMessage();
}
Kickbox returns a response code 200
on success and 429
if you are exceeding the Rate Limit.
If the response code is 200
and the result is deliverable
that means the email address is valid and it really exists.
I hope you understand how to write a real-time email verifier script in PHP. I would like to hear your thoughts or suggestions in the comment section below.
Related Articles
- mailboxlayer – A Free and Powerful API to Check If Email is Valid(Real Email)
- numverify – A Phone Number Validation API
- How to Get Gelocation from IP in PHP
If you liked this article, then please subscribe to our YouTube Channel for video tutorials.
Hey, good article. There is a lot of options in the market for email validation. Check this good blog about 10 bulk email verification: https://www.accuwebhosting.com/blog/top-10-bulk-email-list-verification-validation-services-compared/
It is very simple to use even if you don’t have any programming knowledge. I only use real-time validation with a PHP wrapper class.
Unesseccary emails irritate a lot. Many go to spam and many bounces back too. So to avoid all this we need email verification tools and software. Thank you for sharing this. You can also go through this, https://www.g2crowd.com/products/thechecker-thechecker/reviews, TheChecker.co is great for email verification and email list cleaning services.
Thanks a lot very much for the high your blog post quality and results-oriented help. I won’t think twice to endorse to anybody who wants and needs support about this area. hadoop training in bangalore
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this. rprogramming training in bangalore