Email validation MX Lookup

感情迁移 提交于 2019-12-21 04:17:44

问题


I have been asked to implement some email address validation on a web app - I'm sure we've all been there a thousand times... however, this time I have been asked to do an MX Lookup on the domain to see if it accepts emails.

Does anyone know of any potential problems with doing this? Is an mx lookup a reliable way of finding out if a domain accepts email? are there any edge cases where a valid email address could fail an MX lookup check?

Thanks for your advice!


回答1:


are there any edge cases where a valid email address could fail an MX lookup check?

Yes, in that where there is no MX record, MTAs fall back to using the A record instead. So only allowing MX records would fail a class of mail servers that work in the real world.

Allowing any name with an MX or A record at least detects obvious mistypings that result in NXDOMAIN. However it will still allow mistypings that end up at squatter sites. A further step for addresses resolved by A records might be to check where port 25 is accepting connections on that address.




回答2:


You can only check if there is an mail server registered for the domain.

If the server also accepts mails and if the address is valid (not syntactically but in the sense that there exists a inbox for it and so on...) you will only find out when sending the e.g. registration email

sample on how to do this in PHP

function mailserver_exists($email) {
 list($user,$domain) = split('@',$email);
 //included check for 'A' after [comment from bobince][1]
 return checkdnsrr($domain,'MX') || checkdnsrr($domain,'A');
}
if(domain_exists('joe@foreigndomain.xx')) {...} else {...}

Yes you can use 'TinyTim@192.184.165.13' too. The PHP documentation for checkdnsrr(host, type) states

host may either be the IP address in dotted-quad notation or the host name



来源:https://stackoverflow.com/questions/1666807/email-validation-mx-lookup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!