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条)

报告相同问题?

悬赏问题

  • ¥40 图书信息管理系统程序编写
  • ¥15 7-1 jmu-java-m02-使用二维数组存储多元线性方程组
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题