Last active
February 9, 2020 22:35
-
-
Save finalwebsites/6875c81c5f12a3b28fc3 to your computer and use it in GitHub Desktop.
PHP tutorial code for the email verification tutorial on www.tutdepot.com.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require dirname(__FILE__).'/smtp-validate-email.php'; | |
$from = 'your@emailaddress.com'; | |
if (!$db = new mysqli('localhost', 'username', 'password', 'databasename')) { | |
die('Can\'t connect to the database.'); | |
} else { | |
// after I imported all email addresses into the data I select 25 records for validation | |
$res = $db->query("SELECT ID, email FROM emailaddresses WHERE status = 'valid' ORDER BY RAND() LIMIT 25"); | |
while ($obj = $res->fetch_object()) { | |
$status = 'invalid'; | |
$address = trim($obj->email); | |
// filter for a valid email format | |
if( filter_var( $adres, FILTER_VALIDATE_EMAIL ) ) { | |
$domain = array_pop(explode('@', $address)); | |
// check for existing MX records | |
if (checkdnsrr($domain, 'MX')) { | |
// use the validator class to connect via SMTP | |
$validator = new SMTP_Validate_Email($address, $from); | |
$smtp_results = $validator->validate(); | |
if ($smtp_results[$adres]) { | |
$status = 'valid'; | |
} | |
} | |
} | |
// update the new status, otherwise you will check your records for years :) | |
$db->query(sprintf("UPDATE emailaddresses SET status = '%s' WHERE ID = %d", $status, $obj->ID)); | |
} | |
$db->close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment