如何检查电子邮件标识是否存在? [英] How to check whether an email id exists or not?

查看:168
本文介绍了如何检查电子邮件标识是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用PHP检查电子邮件ID是否存在?并获取有关电子邮件ID所有者的信息?是否可以获取有关电子邮件ID所有者的信息?必须使用像POP这样的协议吗?请帮助我。

How to check whether an email id exists or not using PHP? and to get information about the owner of the email id? is it possible to get the information about the owner of the email id? do have to work with some protocols like POP? Please help me.

推荐答案

让用户提交以下电子邮件地址:

Lets say a user submits the following email address:


  • stackuser@stackoverflow.com

您要按顺序执行的支票就像所以:

The checks you would want to perform in order are like so:


  • 地址是否有效

  • 域运行邮件服务器/ MX Records

  • 是否列入黑名单

首先在PHP中,您可以使用 filter_var 像这样:

Firstly within PHP you can validate an email by using filter_var like so:

$is_valid = filter_var("stackuser@stackoverflow.com",FILTER_VALIDATE_EMAIL);

其次,您需要检查域是否运行电子邮件服务器,为此,您可以检查MX的dns记录如下:

Secondly you would want to check if the domain runs a email server, to do this you can check the dns records for MX like so:

$has_dns_mx_record = checkdnsrr("stackoverflow.com","MX");

您可能还想像这样打开域上的端口:

You might also want to open the port on the domain like so:

$socket = fsockopen("stackoverflow.com", 25);
$mail_running = (bool)$socket;
fclose($socket);

您还可以检查SMTP服务器是否响应550,即电子邮件不存在,像这样:

You can also check to see if the SMTP Server responds with a 550, i.e email does not exist, like so:

SEND > helo hi
250 stackoverflow.com

SEND > mail from: <youremail@yoursite.com>
250 2.1.0 Ok

SEND > rcpt to: <stackuser@stackoverflow.com>
> 550 5.1.1 <stackuser@stackoverflow.com>: Recipient address rejected: User unknown in local recipient table

查看以上您可以发送命令到一个有效的smtp服务器,如 helo > 邮件从< ...> 并检查550响应。

Looking at the above you can send commands to a valid smtp server such as helo > mail from <...> and check the 550 response.

在这里查看一些响应代码: http://www.greenend.org.uk/rjk/2000/05/21/smtp-replies.html

Take a look here for some response codes: http://www.greenend.org.uk/rjk/2000/05/21/smtp-replies.html


此外,您应该注意@ slebetman的评论,指出一小部分邮件>服务器配置为响应550以防止嗅探有效的电子邮件地址。

Also you should take note of @slebetman's comment stating that a small percentage of mail > servers are configured to respond 550 to prevent the sniffing out of valid email addresses.

黑名单检查很简单,你会发现一个体面的DNSBL服务器为您提供一个网关检查检查域名是否已被列入黑名单,如果它的电子邮件可能是va盖子和活动但被标记为垃圾邮件,因此它是一个不可信的电子邮件,您应该要求替代电子邮件地址来授权

The black list check is pretty simple, you would just find a decent DNSBL Server that provides a gateway for you check check the domain to see if it has been blacklisted, if it has the email may well be valid and active but has been marked as spam, therefore its an untrusted email and you should request an alternative email address to authorize against

这些是一些用于验证一个电子邮件地址,现在有更多的验证方法,但这些是主要的一些。

These are some of the validation techniques used to validate an email address, now there is plenty more validation methods but these are a few of the main ones.

这篇关于如何检查电子邮件标识是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆