Basado en https://www.adaweb.es/validar-email-en-php/ con pequeños cambios.
Last active
February 6, 2022 20:03
-
-
Save alelazcano/46ec744ab02bd42e6faa908a6290a6d1 to your computer and use it in GitHub Desktop.
[AyudaEcommerce.com] Validar e-mail con PHP de varias maneras
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (filter_var([email protected]", FILTER_VALIDATE_EMAIL)) { | |
echo '¡E-mail válido!'; | |
}else{ | |
echo 'Verifica el correo ingresado'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$matches = null; | |
if(1 === preg_match('/^[A-z0-9\\._-]+@[A-z0-9][A-z0-9-]*(\\.[A-z0-9_-]+)*\\.([A-z]{2,6})$/', "[email protected]", $matches)){ | |
echo '¡E-mail válido!'; | |
}else{ | |
echo 'Verifica el correo ingresado'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// comprobar si el dominio existe y tiene un registro DNS de tipo MX (mail exchange) | |
function is_valid_email($email){ | |
$result = (false !== filter_var($email, FILTER_VALIDATE_EMAIL)); | |
if ($result){ | |
$domain = explode("@", $email)[1]; | |
$result = checkdnsrr($domain, 'MX'); | |
} | |
return $result; | |
} | |
if(is_valid_email("[email protected]")){ | |
echo '¡E-mail válido!'; | |
}else{ | |
echo 'Verifica el correo ingresado'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment