login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Handige scripts > Email controleren of hij bestaat!

Email controleren of hij bestaat!

Auteur: iemand - 04 september 2004 - 18:51 - Gekeurd door: Dennisvb - Hits: 13034 - Aantal punten: 0.17 (6 stemmen)




Dit script is niet door mij gemaakt! Kom dus ook niet me je vragen naar mij toe . Als jij je aanbied voor de vragen pm mij dan svp.

Ook weet ik niet zeker of dit script al in de core staat! En of hij het doet!?...

Code:
  1. <?php
  2. class mail_check_global
  3. {
  4. var $system_OS = "win"; // required for MX digging (win / linux)
  5. var $debug = 0; // self-explaining (0 - OFF, 1 - ON)
  6. var $recType = "MX"; // limitting dns query to Mail eXchange only
  7. var $email; // the goal! ;)
  8. var $hostName; // parent domain for address
  9. var $userName; // actually NOT used :)
  10. var $check_DNS_result; // debuging DNS check
  11. var $check_MAIL_result; // debuging SYNTAX check
  12.  
  13. // check if MX records in DNS server response (WINDOWS !!!):
  14. function checkDNS()
  15. {
  16. if ($this -> system_OS == "linux") // linuz
  17. {
  18. if (getmxrr($this -> hostName)) return TRUE;
  19. else return FALSE;
  20. } else { // windoz
  21. if(!empty($this -> hostName))
  22. {
  23. exec("nslookup -type=".$this->recType." ".$this -> hostName, $result);
  24. // check each line to find the one that starts with the host
  25. // name. If it exists then the function succeeded.
  26. foreach ($result as $line)
  27. {
  28. if(eregi("^".$this -> hostName,$line)) return true;
  29. }
  30. // otherwise there was no mail handler for the domain
  31. return false;
  32. }
  33. return false;
  34. }
  35. }
  36.  
  37. // brake address --> username & parent domain
  38. function check_email_dns()
  39. {
  40. list($this -> userName, $this -> hostName) = split("@", $this -> email);
  41. if (!$this -> checkDNS ($this -> hostName))
  42. {
  43. $this -> check_DNS_result = "Address domain MX DNS record could NOT be found";
  44. return FALSE;
  45. } else {
  46. $this -> check_DNS_result = "Address DNS MX is OK";
  47. return TRUE;
  48. }
  49. }
  50.  
  51. // check addresse's SYNTAX
  52. function check_email()
  53. {
  54. $this -> email = strtolower($this -> email);
  55. if (preg_match('/^[-!#$%&'*+./0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+.)+([0-9A-Z]){2,4}$/i', $this -> email))
  56. {
  57. $this -> check_MAIL_result = "Address syntax is OK";
  58. return TRUE;
  59. } else {
  60. $this -> check_MAIL_result = "Address syntax is WRONG";
  61. return FALSE;
  62. }
  63. }
  64.  
  65. // global check
  66. function final_mail_check()
  67. {
  68. if (!$this -> check_email_dns() OR !$this -> check_email()) return FALSE;
  69. else return TRUE;
  70. }
  71.  
  72. // debuging ONLY
  73. function debug_address()
  74. {
  75. if ($this -> debug == 1)
  76. {
  77. echo "<br>";
  78. echo "<b>DEBUG</b>:";
  79. echo "<br>";
  80. echo "<u>eMail</u>: ".$this -> email;
  81. echo "<br>";
  82. echo "<u>DNS</u>: ".$this -> check_DNS_result;
  83. echo "<br>";
  84. echo "<u>Syntax</u>: ".$this -> check_MAIL_result ;
  85. echo "<br>";
  86. }
  87. }
  88. } ?>



  1. <?php $check = new mail_check_global; // initiate class
  2. $check -> email = "root@yahoo.com"; // REQUIRED --> address to check
  3. $check -> debug = 1; // OPTIONAL --> default is 0; values: 0 / 1
  4. $check -> system_OS = "win"; // OPTIONAL --> default is WINDOWS; values: win / linux
  5.  
  6. // USE: if($check -> final_mail_check()) ------------------ your action here --------;
  7.  
  8. // USE example:
  9. if ($check -> final_mail_check()) echo "<font style=\"color:green; font-weight:bold\">Email address IS VALID!</font>";
  10. else echo "<font style=\"color:red; font-weight:bold\">The address is NOT VALID!</font>";
  11.  
  12. $check -> debug_address(); // debuging purposes
  13. ?>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (8)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.037s