Forum Moderators: coopster

Message Too Old, No Replies

Checking for valid e-mail address!

need a slight adjustment

         

dreamcatcher

10:50 pm on May 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I`m using the following to check for a valid e-mail address:

if (eregi("^([a-z]¦[0-9]¦\.¦-¦_)+@([a-z]¦[0-9]¦\.¦-¦_)+\.([a-z]¦[0-9]){2,3}$", $_REQUEST['email']) &&
!eregi("(@.*@)¦(\.\.)¦(@\.)¦(\.@)¦(^\.)", $_REQUEST['email']))

Now I`ve got some clown who keeps emailing me with a dud address and he wants to know why I`m not replying. Needles to say I can`t reply.

The address being used is something like:

www.blahblah@yahoo.com

Can you suggest a slight adjustment to the above code that will generate an error if the e-mail starts www.

Thanks

:)

willybfriendly

1:28 am on May 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is the most comprehensive email validator I have come across. That said, I haven't tested it, so caveat emptor

[zend.com...]

WBF

rkeane

1:41 am on May 27, 2003 (gmt 0)

10+ Year Member



Have had the same problem in the past. Have looked at your link and will spend some time looking at it later. This post is just to satisfy a "post within 30 days" or loose it requirement as I'll be gone on vacation for three weeks and don't want to "loose it"

Regards,

rkeane

dreamcatcher

8:11 am on May 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok guys, thanks for the help.

:)

bcc1234

8:22 am on May 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The best you can do is to actually connect to the receiving mail server. That will validate the address.
Basically
HELO ip
MAIL FROM: your@email
RCPT TO: his@mail
<--- catch the response and quit

If it fails (even before that step), you can judge by the error you get.
- wrong host
- no mail server
- no response (that one kills interactivity)
- no such mailbox (that's the best one of all)
- over quota
...

And base your response page on that data.

dmorison

8:49 am on May 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This doesn't explain your yahoo.com problem, but your code is checking for a 2 or 3 character TLD (top level domain), which will cause validation to fail if someone uses an email address at one of the new 4 letter TLD's (i.e. .info).

This is the function I use, which checks against the DNS records for a valid mail exchanger in addition to verifying the email address:


function isvalidemail( $email )
{
if (eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$", $email, $check))
{
if (getmxrr( substr(strstr($check[0], '@'), 1),$mxhosts))
{
return true;
}
}
return false;
}

dreamcatcher

9:05 am on May 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for that dmorison. I`ll use that in future.

:)

dmorison

12:40 pm on May 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By the way, note that this function will not cause an error with www.blahblah@yahoo.com (as per your original question), since to all intents and purposes it is a valid email address. The Yahoo! mail server may of course bounce the email and say "user www.blahblahblah not known".

If you want to trap that specifically you'll need a special case.

daisho

1:05 pm on May 27, 2003 (gmt 0)

10+ Year Member



I used to use a huge regular expression. Much to big and not very reliable.

I now wrote one that does an NS Query. You really only care about the domain since anything before the @ sign _could_ be valid for the receiving mail server (even if it may break rfc).

It is important to check both getmxrr and gethostbyname since many mail servers do not have MX records (which I beleive is valid if not strange) in such cases you deliver to the IP of the A record for the domain.

function CheckEmail ($email) {
list($username,$domain)=explode("@",$email);
if( getmxrr( $domain, $mxhosts ) == FALSE && gethostbyname($domain) == $domain ) {
return FALSE;
} else {
return TRUE;
}
}