Ok, so you have a feedback form, or an suggestion form, yet you find people keep giving you email addresses that you can’t possibly reply to.
Well this php snippit will help you correct this issue.
<?php
define("OK",0);
define("INVALIDEMAIL",1);
define("INVALIDDOMAIN",2);
define("INVALIDMAILBOX",3);
define("UNABLETOVERIFY",4);
function VerifyEmail($Address,$Host = "", $Verify = "") {
if (empty($Host)) {
$Host = $_SERVER["SERVER_NAME"];
}
if (empty($Verify)) {
$Verify = "verifyer@$Host";
}
if (!ereg(
'^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
'@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+'.
'\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $Address)) {
return INVALIDEMAIL;
}
list($Name, $Domain) = explode("@", $Address);
if (!getmxrr($Domain, $MxHosts)) {
return INVALIDDOMAIN;
}
if ($fp = @fsockopen($MxHosts[0],25)) {
$s = fgets($fp,1024);
if (!PutCheck($fp,"HELO $Host","250")) {
return UNABLETOVERIFY;
}
if (!PutCheck($fp,"MAIL FROM: <$Verify>","250")) {
return UNABLETOVREIFY;
}
if (!PutCheck($fp,"RCPT TO: <$Address>","250")) {
return INVALIDMAILBOX;
}
fputs($fp,"RSET");
fputs($fp,"QUIT");
fclose($fp);
} else {
return UNABLETOVERIFY;
}
return OK;
}
function PutCheck($fp,$s,$c) {
fputs($fp,"$s\n");
$s = fgets($fp,1024);
list($Code,$Msg) = explode(" ",$s,2);
return $Code == $c;
}
?>