Jump to content

[SOLVED] check if email exists


adv

Recommended Posts

is there a way to check if a email exists?

on yahoo works because if the id is not taken it will show and with curl u can easly take that result

but on gmail it doesn`t .. it just only say u put in wrong password  or any id ..

 

is there another way of checking if the email exists on domains like gmail ??

 

thanks in advance 

p.s. my english lets me down

Link to comment
Share on other sites

@lodius: You didn't post anything ;)

 

@adv: Are you trying to validate an email for a form submission? If you're trying to make sure that someone typing in an email address for a form, IMO you're creating too much work for yourself. Just let them type in an address and check to see if it's formatted properly.

 

I've used this for a while without any problems. I see people posting email regex all the time and it fails for one of my family member's addresses.

 

preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*(([,]|[,])\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*$/", $email)

Link to comment
Share on other sites

yes from a form submission

i know u can use preg_match to check for @ .. yata yata

 

but i was just wondering if there a way to check for real  like i said on the top about yahoo

and gmail...

that is what i wanna find out :D

Link to comment
Share on other sites

and another question :D i dont wanna open a new thread

 

if i use this

 

function check($value) {
if (empty($value) || strlen($value) < 4) 
	return true;
return false;
}

 

i don`t use the curly brackets inside the function in the if statement .

is it something bad ? it works harder ?  security problems ??

or does it works good ?

Link to comment
Share on other sites

That is true. However, code is harder to read without the curly braces, which results in a higher potential for harder to find errors in the future. So it's good to use them.

 

As to your initial question, I don't believe that you can check if an email address exists with 100% accuracy, but I use this script, and it has worked well for me:

 

	function checkEmail($email)
{
		// First, we check that there's one @ symbol, and that the lengths are right
	if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email))
	{
		// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
		return false;
	}

	// Split it into sections to make life easier
	$email_array = explode("@", $email);
	$local_array = explode(".", $email_array[0]);
	for ($i = 0; $i < sizeof($local_array); $i++)
	{
		if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i]))
		{
			return false;
		}
	}
	if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1]))
	{
		// Check if domain is IP. If not, it should be valid domain name
		$domain_array = explode(".", $email_array[1]);
		if (sizeof($domain_array) < 2)
		{
			return false; // Not enough parts to domain
		}
	}
	for ($i = 0; $i < sizeof($domain_array); $i++)
	{
		if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i]))
		{
			return false;
		}
	}

	list($Username, $Domain) = split("@",$email);

	if(!checkdnsrr($Domain, 'MX'))
	{
		return false;
	}
	return true;
}

 

I've never had any problems, and it has caught everything I have ever tried throwing at it. See if it works for you. It definitely catches non existent domains, but it doesn't seem to catch non-existent email addresses, although its been a while since I tested it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.