Syntax-K

Know-How für Ihr Projekt

Perl Documentation

NAME

Email::Valid - Check validity of Internet email addresses

SYNOPSIS

use Email::Valid;
print (Email::Valid->address('maurice@hevanet.com') ? 'yes' : 'no');

DESCRIPTION

This module determines whether an email address is well-formed, and optionally, whether a mail host exists for the domain.

Please note that there is no way to determine whether an address is deliverable without attempting delivery (for details, see perlfaq 9).

PREREQUISITES

This module requires perl 5.004 or later and the Mail::Address module. Either the Net::DNS module or the nslookup utility is required for DNS checks. The Net::Domain::TLD module is required to check the validity of top level domains.

METHODS

Every method which accepts an <ADDRESS> parameter may
be passed either a string or an instance of the Mail::Address
class.  All errors raise an exception.

EXAMPLES

Let's see if the address 'maurice@hevanet.com' conforms to the RFC822 specification:

print (Email::Valid->address('maurice@hevanet.com') ? 'yes' : 'no');

Additionally, let's make sure there's a mail host for it:

print (Email::Valid->address( -address => 'maurice@hevanet.com',
                              -mxcheck => 1 ) ? 'yes' : 'no');

Let's see an example of how the address may be modified:

$addr = Email::Valid->address('Alfred Neuman <Neuman @ foo.bar>');
print "$addr\n"; # prints Neuman@foo.bar

Now let's add the check for top level domains:

$addr = Email::Valid->address( -address => 'Neuman@foo.bar',
                               -tldcheck => 1 );
print "$addr\n"; # doesn't print anything

Need to determine why an address failed?

unless(Email::Valid->address('maurice@hevanet')) {
  print "address failed $Email::Valid::Details check.\n";
}

If an error is encountered, an exception is raised. This is really only possible when performing DNS queries. Trap any exceptions by wrapping the call in an eval block:

eval {
  $addr = Email::Valid->address( -address => 'maurice@hevanet.com',
                                 -mxcheck => 1 );
};
warn "an error was encountered: $@" if $@;

BUGS

Email::Valid should work with Perl for Win32. In my experience, however, Net::DNS queries seem to take an extremely long time when a record cannot be found.

AUTHOR

Copyright 1998-2003, Maurice Aubrey <maurice@hevanet.com>. All rights reserved.

This module is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

CREDITS

Significant portions of this module are based on the ckaddr program written by Tom Christiansen and the RFC822 address pattern developed by Jeffrey Friedl. Neither were involved in the construction of this module; all errors are mine.

Thanks very much to the following people for their suggestions and bug fixes:

Otis Gospodnetic <otis@DOMINIS.com>
Kim Ryan <kimaryan@ozemail.com.au>
Pete Ehlke <pde@listserv.music.sony.com> 
Lupe Christoph
David Birnbaum
Achim
Elizabeth Mattijsen (liz@dijkmat.nl)

SEE ALSO

Mail::Address, Net::DNS, Net::Domain::TLD, perlfaq9