The best way to check whether or not an e-mail address is valid is to make sure it is of a valid format. You can do this using regular expressions:

use strict; use warnings; use CGI; my $CGI_obj = CGI->new; my $email = $CGI_obj->param('email'); # or is it params? if ($email =~ m/.*?@.*?\..*?/) { print "This e-mail is valid\n"; } else { print "This is not a valid e-mail\n"; }

You really should check out one of the regular expressions tutorials, i.e.: perlretut Remember that PerlDoc.com and Google are your friends.

Now, you might be saying to yourself, "But how do I know that the e-mail address will work?". The only real way to do that is to send an e-mail to the address you're checking.

The reasons for this are mostly related to efforts at spam prevention. There is some command you can send to port 25 (the email port) if you open up a socket to "ping" it and see if it accepts emails. However, because many networks dont want spammers looking for their e-mail addresses they may disable it. You can look up a domain name to see if you can get an IP address, but this doesn't always work for exotic domains unless your script is very robust.

You can even open up port 25 to send email, and just never complete it, but, again, for spam related purposes if you're not on the network the server isn't guaranteed to respond, even with a "No relaying allowed" message. The other thing to look out for is the email address may be valid but not the original users. So they may be redirecting it to a cache all e-mail (some servers forward all email to root@localhost or webmaster@localhost if the user is not valid). Or they may never read their e-mail.

So, stick with regular expressions. Or you can send out an e-mail to the user asking them to confirm their submission. However, that is a whole nother can of worms and suitable for another thread.

Best Regards,

Vautrin

In reply to Re: Re: Re: Create required fields from form by Vautrin
in thread Create required fields from form by hcb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.