Php validar email por dns beta 0.1


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



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.