简体   繁体   English

Windows上的php中的电子邮件域验证

[英]email domain validation in php on windows

I am asking for an email address through a form in my website. 我正在通过网站上的表格要求电子邮件地址。 I want to validate the domain so that I can prevent fake entries I am getting right now. 我想验证域,以便防止我现在得到的虚假条目。 I am using the following code, but it dose not seem to work : 我正在使用以下代码,但似乎无法正常工作:

function myCheckDNSRR($hostName, $recType = '')
{
    if(!empty($hostName)) {
        if( $recType == '' ) $recType = "MX";
        exec("nslookup -type=$recType $hostName", $result);
        // check each line to find the one that starts with the host
        // name. If it exists then the function succeeded.
        foreach ($result as $line) {
            if(eregi("^$hostName",$line)) {
                echo "valid email";
            }
        }
        // otherwise there was no mail handler for the domain
        echo "invalid email";
    }
    echo "invalid EMAIL";
}

I am new to this and used this code from here 我对此很陌生,并从这里使用了这段代码

Please guide me. 请指导我。 Thanks. 谢谢。

I guess you can simply ping like this. 我猜您可以像这样简单地ping。

 function myCheckDNSRR($email_address)
    { 
        if(!empty($email_address)) {
            $hostName=strstr($email_address, '@');
            $hostName=str_replace("@","www.",$hostName);
            exec("ping " . $hostName, $output, $result);
            if ($result == 0){
                 echo "valid email";
            }
            else{
                 echo "invalid email";
            }
    } 
 }

call it like 称它为

  echo myCheckDNSRR("sample@gmail.com");

Use a validation lib like https://docs.zendframework.com/zend-validator/validators/email-address/ 使用验证库,例如https://docs.zendframework.com/zend-validator/validators/email-address/

$validator = new Zend\Validator\EmailAddress();

if ($validator->isValid($email)) {
    // email appears to be valid
} else {
    // email is invalid; print the reasons
    foreach ($validator->getMessages() as $message) {
        echo "$message\n";
    }
}

Create a table in your DB for storing an email link code. 在数据库中创建一个表,用于存储电子邮件链接代码。 When someone registers, mark the user as unactivated until he clicks the link in the email. 当某人注册时,将用户标记为未激活,直到他单击电子邮件中的链接。 This way, you know it's real, and can activate the user. 这样,您就知道它是真实的,并且可以激活用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM