Email Verification API in PHP

Developers that are looking for a email verification API in PHP to integrate with a website or application that works in real-time, you are in luck.

To setup a email verification within PHP you can request a trial key for the API and begin mixing with your code inside your application using the following sample to get you started:

<?php

// URL which should be requested

$url = ‘http://api.emailyoyo.com/api/a/v1’;

$apikey = ‘YOUR API KEY’; // API Key

$email = ‘Email Address to Test’; // Email to test

// jSON String for request

$url .= “?email=$email&key=$apikey”;

// Initializing curl

$ch = curl_init( $url );

if($ch == false) {

die (“Curl failed!”);

} else {

// Configuring curl options

$options = array(

CURLOPT_RETURNTRANSFER => true,

CURLOPT_HTTPHEADER => array(‘Content-type: application/json’)

);

// Setting curl options

curl_setopt_array( $ch, $options );

// Getting results

$result = curl_exec($ch); // Getting jSON result string

// display JSON data

echo “$result”;

}

?>

If you have to use SSL, adjust the http:// in your code to https:// with no other changes. Running a email verification API in PHP against your own server won’t work. You will need to partner with a service like Email YoYo to go beyond email validation Regex to verify email addresses during the point of entry.

Email Verification API in PHP using RESTful

There is a method on Stack Overflow on how to validate an email in PHP but it does not cover real-time verification with a service provider that verify emails instantly from a hosted server.

Email Verification API in PHP Versions

While the API works with all versions of PHP when done properly, not that both PHP 5.3.3 and 5.2.14 had a bug tied to FILTER_VALIDATE_EMAIL, and this resulted in segfault when validating large values of emails.

There is a safe workaround for the FILTER_VALIDATE_EMAIL bug when it is using strlen() before filter_var(). In the 5.3.4 final release it will be fixed, but it is written that some 5.3.4 beta versions are affected.

This code will run a simple verification in PHP of email without an API. The results will not be accurate or favorable for actually using the address afterwards for live data drafting.

function isValidEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL)
&& preg_match(‘/@.+\./’, $email);
}

To receive a accurate response you must run a email verification API in PHP using a RESTful service that you can find out more about here.