donglao6169 2017-02-24 11:15
浏览 194
已采纳

使用checkdnsrr验证电子邮件,这是一个好的或坏的解决方案?

I am using the below code to validate emails

if (checkdnsrr($domain , "MX")) {
    echo 'mx - pass <br>';
} else {
    echo 'mx - fail <br>';
}

My desire is to check that the domain is valid and has an MX record.

I am already using a regular expression to check the email format, but people enter things like someone@gmail.con which obviously is wrong but pases basic format validation.

I want to validate further but I do not want to go too far and get false negatives.

Does anyone see any issue with my solution or have a better way?

  • 写回答

3条回答 默认 最新

  • dro59505 2017-02-24 11:17
    关注

    Your solution is perfectly fine! However, before you even make a DNS call, I'd recommend that you first validate the email address with FILTER_VALIDATE_EMAIL and then pass it for MX DNS check.

    While, it may not be needed to check if the MX record exists, but you're looking to avoid bounce emails, go ahead!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?