homepage Welcome to WebmasterWorld Guest from 54.167.144.202
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Help with email validation code
leafgreen

5+ Year Member



 
Msg#: 3548988 posted 7:50 pm on Jan 15, 2008 (gmt 0)

What's the purpose of the part with "example.com"? Is it to make an exception for email addresses ending with example.com? If so, how can I excise this part only, keeping the rest of the script functional?
TIA!

[fixed]
function ValidateMail($Email)
{
global $HTTP_HOST;
$result = array();
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email))
{
$result[0]=false;
$result[1]="$Email is not properly formatted";
return $result;
}
list ( $Username, $Domain ) = split ("@",$Email);
if($Email!="[b]example.com[/b]")
{
$result[0]=true;
$result[1]="$Email appears to be valid.";
return $result;
}
else
{
if (getmxrr($Domain, $MXHost))
{
$ConnectAddress = $MXHost[0];
}
else
{
$ConnectAddress = $Domain;
}
$Connect = fsockopen ( $ConnectAddress, 25 );
if ($Connect)
{
if (ereg("^220", $Out = fgets($Connect, 1024)))
{
fputs ($Connect, "HELO $HTTP_HOST\r\n");
$Out = fgets ( $Connect, 1024 );
fputs ($Connect, "MAIL FROM: <{$Email}>\r\n");
$From = fgets ( $Connect, 1024 );
fputs ($Connect, "RCPT TO: <{$Email}>\r\n");
$To = fgets ($Connect, 1024);
fputs ($Connect, "QUIT\r\n");
fclose($Connect);
if (!ereg ("^250", $From)
!ereg ( "^250", $To ))
{
$result[0]=false;
$result[1]="Server rejected address.";
return $result;
}
}
else
{
$result[0] = false;
$result[1] = "No response from server.";
return $result;
}
}
else
{
$result[0]=false;
$result[1]="Sorry, but for some reason we cannot connect to your email server.";
return $result;
}
$result[0]=true;
$result[1]="$Email appears to be valid.";
return $result;
}
}
?>
[/fixed]

[edited by: coopster at 12:54 am (utc) on Jan. 16, 2008]

[edited by: eelixduppy at 1:41 pm (utc) on Jan. 17, 2008]
[edit reason] generalized domain [/edit]

 

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3548988 posted 1:45 pm on Jan 17, 2008 (gmt 0)

The script checks to make sure that the email string (the entire thing) isn't example.com. So name@example.com is still valid according to this script.

PHP_Chimp

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3548988 posted 5:55 pm on Jan 17, 2008 (gmt 0)

You may want to think about your email validation routine a little, as there are plenty of valid characters that you are not allowing. While most people emails only have [a-z0-9_-] in them that is not the only characters allowed. So if you are going to tell people
$result="$Email is not properly formatted";

when there email is perfectly well formatted you are going to annoy people.
Seeing as you are actually doing a lookup on the address that people specify why dont you do the lookup first then tel them there email address doesnt work. Or if you dont want to do that then instead of kicking them out give a "Are you really sure this email address is correct" message, then if they say yes do your lookup.

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3548988 posted 5:59 pm on Jan 17, 2008 (gmt 0)

Just a note. The following link is a very good resource for email validation regex: [regular-expressions.info...]

There are some interesting points brought up, too.

mjwalshe

5+ Year Member



 
Msg#: 3548988 posted 5:10 pm on Jan 18, 2008 (gmt 0)

id use a regex to do this theres a good if EXTREAMLY SCARRY! one in the small owls book - which has an entire chaper on email validation.

[oreilly.com...]

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3548988 posted 1:06 pm on Jan 19, 2008 (gmt 0)

there is also this thread from our Library
[webmasterworld.com...]

it has links to a couple other great threads

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved