How to check if an email address exists without sending an email?

前端 未结 14 1748
半阙折子戏
半阙折子戏 2020-11-22 00:28

I have come across this PHP code to check email address using SMTP without sending an email.

Has anyone tried anything similar or does it work for you? Can you tell

14条回答
  •  既然无缘
    2020-11-22 01:31

    function EmailValidation($email)
    {
        $email = htmlspecialchars(stripslashes(strip_tags($email))); //parse unnecessary characters to prevent exploits
        if (eregi('[a-z||0-9]@[a-z||0-9].[a-z]', $email)) {
            //checks to make sure the email address is in a valid format
            $domain = explode( "@", $email ); //get the domain name
            if (@fsockopen ($domain[1],80,$errno,$errstr,3)) {
                //if the connection can be established, the email address is probably valid
                echo "Domain Name is valid ";
                return true;
            } else {
                echo "Con not a email domian";
                return false; //if a connection cannot be established return false
            }
            return false; //if email address is an invalid format return false
        }
    }
    

提交回复
热议问题