I've often wondered at this function... There's an example of a fully RFC822 compliant regexp here: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html The point being that regexps and email addresses don't play well together. There basically is not a worthwhile regexp that handles email addresses. Regexp people seem to say that using them to validate email address, like using them to validate HTML, is using the wrong tool for the job. Obviously we can't know an email address is valid, working and being read without sending a confirmation email, which is the only tool for that job, but the compromise approach is to use DNS. We can't use getmxrr() (which checks the existence of MX records for the domain) because it doesn't work on Windows. However, we could use gethostbyname() on the domain part of the address. This would: 1- Work on all supported platforms (PHP>=3) 2- Guarantee that the email was going to an actual domain 2a- Therefore catch spelling errors, which improves user experience and site conversion rates 3- Leave the option of using a regexp on the username part But still need special handling of user@localhost and user@127.0.0.1 type addresses. I'm sorry to be anecdotal about it, but when I implemented a getmxrr() approach on one site, we got a big (>20% by memory) improvement in valid email addresses through, mainly by eliminating typos. I would be happy to write a patch for this if people are interested, but I wanted to expose the idea to discussion first. Cheers, Will (willmoy)
-----Original Message----- From: drupal-devel-bounces@drupal.org [mailto:drupal-devel-bounces@drupal.org]On Behalf Of killes Sent: 10 May 2005 22:07 To: drupal-devel@drupal.org Subject: [drupal-devel] [bug] other valid emails fail too
Issue status update for http://drupal.org/node/21067
Project: Drupal Version: 4.6.0 Component: base system Category: bug reports Priority: critical Assigned to: CdnStrangequark Reported by: jwells Updated by: killes@www.drop.org -Status: active +Status: patch Attachment: http://drupal.org/files/issues/valid_email.patch (1.31 KB)
Our intrepid Debian developer has cooked up a patch. It is based on RFC 2822 but it needs testing.
killes@www.drop.org
Previous comments: -------------------------------------------------------------- ----------
April 22, 2005 - 07:00 : jwells
When attemping to use a sub-domain email address for a new account, it won't pass the syntax test. We know that its really the base - but I'm sure a lot of end uers don't know.
newaccount@research.drupal.org - this type of address will fail, though it is actually legal
-------------------------------------------------------------- ----------
May 10, 2005 - 17:00 : CdnStrangequark
Not just sub-domain emails. If you have an email address of the form: "first.last@somewhere.com" it will also fail even though this is perfectly valid.
-------------------------------------------------------------- ----------
May 10, 2005 - 18:30 : CdnStrangequark
After attempting to enter more emails on one of my new sites, I also discovered that the validation fails in yet more perfectly valid cases. For example: "myemail@somewhere.xx" where xx is the country domain code. (like .ca, or .us). Not all country codes are accepted.
Here is a replacement I made for the code in common.inc: *valid_email_address($mail)* that works just great:
$user = "[-a-z0-9!#$%&'*+/=?^_`{|}~]"; $domain = "([a-z]([-a-z0-9]*[a-z0-9]+)?)"; $regex = "^$user+(\.$user+)*@($domain{1,63}\.)+$domain{2,63}$"; //Return a 1 or 0 to mimic results of preg_match if (eregi($regex, $mail)) { return 1; } else { return 0; }
The only thing this doesn't do is allow for "user@localhost" but does anyone really do that anyway? The code could be modified to do it through an alternate check on $domain though.
PS: I left this post's status as active and unassigned cause I'm kinda new here and don't know the process for submitting patches and bug fixes. Hope someone can put this code in the core though cause I'm sure we're not the only ones who have run into the problem.