How can I verify an email address in PHP? [duplicate]
Possible Duplicate:
Is there a PHP libr开发者_如何学Goary for email address validation?
How can I verify an email address in PHP?
If you want to check if an email address exists, check out checkdnsrr:
if (checkdnsrr('you@user.com', 'MX')) {
echo ':)';
}
else {
echo ':(';
}
If you want to check if a string is an email address, there are literally millions of regulars expressions out there. There's a native function in php, filter_input that does it, thought I've personally never used it.
filter_var($input, FILTER_VALIDATE_EMAIL)
function isemail($email) {
return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
}
精彩评论