https://github.com/zytzagoo/smtp-validate-email/blob/master/smtp-validate-email.php 以检查邮件地址的存在并进行一些修改
<?php
require('smtp-validate-email.php');
$from = 'removed'; // for SMTP FROM:<> command
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mailverf', $con);
$sql="SELECT *
FROM `mailvalid` where statut=0 limit 0,30";
$result = mysql_query($sql);
if($result === FALSE) {
die(mysql_error());
while($row = mysql_fetch_array($result))
{
$email = $row['mail'];
$validator = new SMTP_Validate_Email($email, $from);
$smtp_results = $validator->validate();
$mail=str_replace(' ','',$row['mail']);
// var_dump($smtp_results);
if($smtp_results[$email])
{
$sql1="UPDATE mailvalid SET statut = 1 WHERE id =".$row['id']."";
mysql_query($sql1) or die(mysql_error());
}
else
{
$sql2="INSERT INTO mailnonvalid (mail) VALUES ('".$row['mail']."')";
mysql_query($sql2) or die(mysql_error());
$sql3="DELETE FROM mailvalid WHERE id = ".$row['id']."";
mysql_query($sql3) or die(mysql_error());
}
// var_dump($email);
echo $row['id'].'</br>';
}
$sql="SELECT *
FROM `mailvalid` where statut=0 limit 0,30";
$result = mysql_query($sql);
if($result === FALSE) {
die(mysql_error());
}
if($row = mysql_fetch_array($result)){
echo '<script>window.location.reload(); </script>';}else {echo 'end';}
}
}
?>
它很好用,除了一段时间后出现此错误消息:
Fatal error: Uncaught exception 'SMTP_Validate_Email_Exception_Timeout' with message 'Timed out in recv' in C: \ xampp \ htdocs \ verif \ smtp-validate-email.php: 626
Stack trace:
# 0 C: \ xampp \ htdocs \ verif \ smtp -validate-email.php (650) SMTP_Validate_Email-> recv (3)
# 1 C: \ xampp \ htdocs \ verif \ smtp-validate-email.php (554) SMTP_Validate_Email-> expect (Array, 3)
# 2 C: \ xampp \ htdocs \ verif \ smtp-validate-email.php (311) SMTP_Validate_Email-> rset ()
# 3 C: \ xampp \ htdocs \ verif \ index.php (28): SMTP_Validate_Email-> validate ()
# 4 {main} thrown in C: \ xampp \ htdocs \ verif \ smtp-validate-email.php on line 626