Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP built in function to determine if email is valid [duplicate]

Tags:

php

Possible Duplicate:
How to validate an Email in PHP?

Does PHP have a built in function for determining if an email address is formatted properly. I know it can't go out and check if the email is actually active; I'm talking about just confirming that an email address is structurally correct.

like image 528
Ralph M. Rivera Avatar asked Aug 19 '11 00:08

Ralph M. Rivera


People also ask

How can I check if an email address is valid in PHP?

PHP - Validate E-mail The easiest and safest way to check whether an email address is well-formed is to use PHP's filter_var() function.

How would you test if the output of the email would be valid for different email providers?

How can I check if an email address is valid for free? Use an email validation service. Many services provide a web tool on their website where you can quickly verify the address in real time. The service does all the work of checking the syntax and reviewing the MX records.


1 Answers

filter_var can do this:

$result = filter_var( '[email protected]', FILTER_VALIDATE_EMAIL );

It returns false when it failed validation, and returns the e-mail address otherwise.

like image 78
Decent Dabbler Avatar answered Oct 15 '22 22:10

Decent Dabbler