Re: Email checking

From: Date: Thu, 13 Sep 2001 15:48:56 +0000
Subject: Re: Email checking
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-67240@lists.php.net to get a copy of this message
On Thu, 13 Sep 2001 11:28:01 -0700, you wrote: >like to be able to check to see that: the email is in the correct format and >the domain actually exists. Can anyone lend a hand? [putting the "try it this way" bit first] The only way to "validate" an email address is to try to send email to it. If you are doing anything where users add themselves to a mailing list, then best practice is to use a double-opt-in. (this is what you had to do when signing up to the PHP list). a) user requests that their email address is signed up b) a email with a unique subject line is sent to the address c) when the email is replied to, the account goes live This way, nobody can be added to the database maliciously, and you are guaranteed to have a working email address. However... if (!ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $email)) { $result = 'Not a valid email address'; } checks that an email address parses ok. list(,$domain) = split('@', $email); should put the domain component in $domain. Now, you have to check that an MX record exists for that domain. Here's a script that will give you some idea of what you will be receiving: http://www.declude.com/tools/lookup.php If you want to be really paranoid, you can then connect to the host(s) in the MX record on port 25 and check they have SMTP servers running. Even when you've done all this: 1) The user portion of the address may be incorrect (a few SMTP servers offer VRFY though). 2) The MX record may be wrong, and the SMTP server might refuse mail for that domain djo

« previous php.general (#67240) next »