PHP : Powerfull testing mails


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // PHP.ini : allow_call_time_pass_reference = On
  2. // somenone can override this ?
  3. function neo_mailCheck($Email){
  4. // email well formatted ? can use SANITIZE stuff
  5. if(!preg_match('`^[[:alnum:]]([-_.]?[[:alnum:]])*@[[:alnum:]]([-_.]?[[:alnum:]])*\.([a-z]{2,4})$`', $Email)){
  6. exit('Email adress '.$Email.' not well formatted');
  7. }
  8. // Get domain
  9. list(,$domain ) = split('@',$Email);
  10. // Cherching data MX in DNS
  11. if (getmxrr($domain, $MXHost)){
  12. $ConnectAddress = $MXHost[0];
  13. } else {
  14. $ConnectAddress = $domain;
  15. }
  16. // Creating connexion on smtp port (25)
  17. $Connect = @fsockopen($ConnectAddress,25,&$errno,&$errstr);
  18. if($Connect){
  19. // test return 220
  20. if(preg_match('/^220/', $Out = fgets($Connect, 1024))){
  21. fputs ($Connect, "HELO {$_SERVER['HTTP_HOST']}
  22. ");
  23. $Out = fgets ( $Connect, 1024 );
  24. fputs ($Connect, "MAIL FROM: <{$Email}>
  25. ");
  26. $From = fgets ( $Connect, 1024 );
  27. fputs ($Connect, "RCPT TO: <{$Email}>
  28. ");
  29. $To = fgets ($Connect, 1024);
  30. fputs ($Connect, "QUIT
  31. ");
  32. fclose($Connect);
  33. // If command RCPT TO returns 250 ou 251 (cf: RFC)
  34. // Son email exist
  35. if (!preg_match ('/^250/', $To) && !preg_match ('/^251/', $To)){
  36. // Adress rejected by server
  37. return false;
  38. } else {
  39. // Adress accepted by server
  40. return true;
  41. }
  42. } else {
  43. // Server not answered
  44. return false;
  45. }
  46. } else {
  47. // Login on mail server impossible
  48. // You can see error with this :
  49. // echo $errno."-".$errstr;
  50. return false;
  51. }
  52. }

URL: http://www.giacomel.fr

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.