Email validation MX Lookup

后端 未结 2 1015
后悔当初
后悔当初 2021-02-14 22:15

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

2条回答
  •  渐次进展
    2021-02-14 22:55

    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

提交回复
热议问题