Posted By

nicolaspar on 07/12/06


Tagged


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

luman
postNuKe
millisami
willcodeforfood
hiramvb


Php validar email por dns beta 0.1


 / Published in: PHP
 

  1. # validar emails con dominios validos
  2. function validateDnsEmail( $emailRaw ) {
  3. # Sacamos espacios y saltos
  4. $emailNr = eregi_replace( "\n", "", $emailRaw );
  5. $emailNr = eregi_replace( "\r", "", $emailRaw );
  6. $email = eregi_replace( " +", "", $emailNr );
  7. $email = strtolower( $email );
  8. # Lo pasamos por una regex para validar el formato
  9. if( ! eregi( "^[a-z0-9]+([_\\.-][a-z0-9]+)*". "@([a-z0-9]+([\.-][a-z0-9]+))*$", $email ) ){
  10. # Si no es valido....
  11. $feedback = 0;#'Error: "' . $email . '" is not a valid e-mail ';
  12. return $feedback;
  13. }else{
  14. #Si esta ok, sacamos el dominio
  15. $item = explode( "@", $email );
  16. $domain = $item["1"];
  17. if ( ( gethostbyname( $domain ) == $domain ) ){
  18. if ( gethostbyname( "www." . $domain ) == "www." . $domain ){
  19. $feedback = 0;#'Error: "' . $domain . '" is most probably not a valid domain!';
  20. return $feedback;
  21. }
  22. #Es Valido
  23. $feedback = 1;
  24. return $feedback;
  25. }else{
  26. #valido
  27. $feedback = 1;
  28. return $feedback;
  29. }
  30. }
  31. }

Report this snippet  

You need to login to post a comment.