IPv4 Fremnet Logo
TOOLS, TINKERINGS & CODE

Help me help you

Verify Email Addresses · Mar 13, 21:02 by Shannon Wynter

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.

  1. <?php
  2. define("OK",0);
  3. define("INVALIDEMAIL",1);
  4. define("INVALIDDOMAIN",2);
  5. define("INVALIDMAILBOX",3);
  6. define("UNABLETOVERIFY",4);
  7.   
  8. function VerifyEmail($Address,$Host = "", $Verify = "") {
  9. if (empty($Host)) {
  10.   $Host = $_SERVER["SERVER_NAME"];
  11. }
  12. if (empty($Verify)) {
  13.   $Verify = "verifyer@$Host";
  14. }
  15. if (!ereg(
  16.   '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
  17.   '@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+'.
  18.   '\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $Address)) {
  19.   return INVALIDEMAIL;
  20. }
  21. list($Name, $Domain) = explode("@", $Address);
  22. if (!getmxrr($Domain, $MxHosts)) {
  23.   return INVALIDDOMAIN;
  24. }
  25. if ($fp = @fsockopen($MxHosts[0],25)) {
  26.   $s = fgets($fp,1024);
  27.   if (!PutCheck($fp,"HELO $Host","250")) {
  28.   return UNABLETOVERIFY;
  29.   }
  30.   if (!PutCheck($fp,"MAIL FROM: <$Verify>","250")) {
  31.   return UNABLETOVREIFY;
  32.   }
  33.   if (!PutCheck($fp,"RCPT TO: <$Address>","250")) {
  34.   return INVALIDMAILBOX;
  35.   }
  36.   fputs($fp,"RSET");
  37.   fputs($fp,"QUIT");
  38.   fclose($fp);
  39. } else {
  40.   return UNABLETOVERIFY;
  41. }
  42. return OK;
  43. }
  44.   
  45. function PutCheck($fp,$s,$c) {
  46. fputs($fp,"$s\n");
  47. $s = fgets($fp,1024);
  48. list($Code,$Msg) = explode(" ",$s,2);
  49. return $Code == $c;
  50. }
  51. ?>
  52. Download this code: verifyemail.php (Downloaded 249 time(s))
Comments

Spam no more - rel=nofollow is active here, spamming my comments will not help your page rank.

  Textile help
---== Copyright Shannon Wynter - All rights reserved - All wrongs avenged ==--- info