Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Created July 6, 2021 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finalwebsites/b18d74f101100c2a89b5ad6dd2a7ba93 to your computer and use it in GitHub Desktop.
Save finalwebsites/b18d74f101100c2a89b5ad6dd2a7ba93 to your computer and use it in GitHub Desktop.
Check your email list with the email validation service from mailboxlayer
<?php
set_time_limit(0);
ini_set('memory_limit', '2048M'); // if your list is very long
$api_key = 'PLACE HERE YOUR API';
$fp = fopen('emailchecked.csv', 'w');
fputcsv($fp, array('Email address', 'Valid MX', 'Valid SMTP', 'Score'));
$count = 0;
if (($handle = fopen("emaillist.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$ch = curl_init('https://apilayer.net/api/check?access_key='.$api_key.'&email='.$data[0]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close($ch);
$validationResult = json_decode($json, true);
$row = array($data[0], $validationResult['mx_found'], $validationResult['smtp_check'], $validationResult['score']);
fputcsv($fp, $row);
$count++;
if ($count % 4 == 1) sleep(1); // Don't reach the 300 requests/minute rate limit
}
}
fclose($fp);
@finalwebsites
Copy link
Author

Your "basic" email list needs only a single column for the email addresses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment