Jump to content

Function


lostprophetpunk

Recommended Posts

I am working on a function to check emails, but I have come across a problem.

 

The problem is that it always returns the $valid as 0, even when the email address is valid.

 

Here is the code involved...

function ccheckdnsrr($host, $type='mx'){
    $res=explode("\n",strstr(shell_exec('nslookup -type='.$type.' '.escapeshellarg($host).' 4.2.2.3'),"\n\n"));
    if($res[2]){
        return TRUE;
    }else{
        return FALSE;
    }
}

function checkemail($email)
{
$address = $email;
$count = substr_count($address, '@');

if($count == 1 )
{	
	$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
	if (eregi($regexp, $email))
	{
		list($name,$domain) = explode("@",$email);
		$ip = gethostbyname($domain);
		$meh = ccheckdnsrr($name);
		if($meh == false)
		{
			$valid = 0;
		}else {
			$valid = 1;
		}
	}else {
		$valid = 0;
	}		
}else {
$valid = 0;
}
return $valid;
}

 

If anyone could help, that would be awesome.

Link to comment
https://forums.phpfreaks.com/topic/170804-function/
Share on other sites

Hi

 

You are using the first part of the email address on the dns check. Ie, if you were looking for [email protected] you have checked for fred rather than burt.com

 

if (eregi($regexp, $email))

{

list($name,$domain) = explode("@",$email);

$ip = gethostbyname($domain);

$meh = ccheckdnsrr($domain);

if($meh == false)

{

$valid = 0;

}else {

$valid = 1;

}

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/170804-function/#findComment-900800
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.