PHP Email Validator–电子邮件MX DNS记录检查
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Email Validator–电子邮件MX DNS记录检查相关的知识,希望对你有一定的参考价值。
Validating an email address is one of the hardest feats on the web. A valid email can be marketinggold, but an invalid email address is dead weight. Not only does it require a CPU-taxing php regular
expression ("/^[A-z0-9._-]+"."@" . "[A-z0-9][A-z0-9-]*". "(.[A-z0-9_-]+)*".".([A-z]{2,6})$/"),
the regular expression can be useless even after it's validated for format if the domain doesn't
exist.
A regular expression simply wont do -- we need to think more low-level. What does email at any
domain require? A DNS MX record. Well, PHP provides a great solution to validate that there's a MX
record for the provided email address' domain.
<?php function domain_exists($email, $record = 'MX'){ } echo('This MX records exists; I will accept this email as valid.'); } else { echo('No MX record exists; Invalid email.'); }
以上是关于PHP Email Validator–电子邮件MX DNS记录检查的主要内容,如果未能解决你的问题,请参考以下文章
WTForms:安装“email_validator”以获得电子邮件验证支持
email_validator 挤压 tefxformfield 颤动