You want to know whether an email address a user has provided is valid.
Use the is_valid_email_address( ) function in Example 9-10. It tells you whether an email address is valid according to the rules in RFC 822.
Validating an email address
RFC 822 defines the standards for a valid email address. The function in Example 9-10, by Cal Henderson, uses the grammar rules laid out in that RFC to build a regular expression. You can read more about how the function is constructed at http://www.iamcal.com/publish/articles/php/parsing_email. Cal has also written a function that validates according to the more complicated rules in RFC 2822. That function is available for download from http://code.iamcal.com/php/rfc822/rfc822.phps.
The function in Example 9-10 only checks that a particular address is syntactically correct. This is useful for preventing a user from accidentally telling you that her email address is bingolover2261@example instead of email@example.com. What it doesn't tell you, however, is what happens if you send a message to that address. Furthermore, it doesn't let you know that the person providing the email address is in control of the address. For those sorts of validations, you need to send a confirmation message to the address. The confirmation message can ask the user to take some affirmative task (reply to the message, click on a link) to indicate they're the same person that entered the address on the form. Or, the confirmation message can tell the user what to do (reply to the message, click on a link), if she's not the same person that entered the address on the form. Recipe 8.17 demonstrates a system that sends an email message containing a link that the recipient must click on to confirm that she provided the address.
9.4.4. See Also
RFC 822 at http://www.faqs.org/rfcs/rfc822.html, RFC 2822 at http://www.faqs.org/rfcs/rfc2822.html, "Parsing Email Addresses in PHP" by Cal Henderson at http://www.iamcal.com/publish/articles/php/parsing_email, and the functions available for download at http://code.iamcal.com/php/rfc822/.