I am trying to make a feedback form for my website, and I want to make the form check if the email is valid (If it has @ and .) Here is the code: http://pastebin.com/9kTEh631
Thank you.
I am trying to make a feedback form for my website, and I want to make the form check if the email is valid (If it has @ and .) Here is the code: http://pastebin.com/9kTEh631
Thank you.
A way to The best way to validate an email address is using PHP's built in validation:
http://php.net/manual/en/filter.examples.validation.php
<?php
$email_a = 'joe@example.com';
$email_b = 'bogus';
if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
echo "This ($email_a) email address is considered valid.";
}
if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
echo "This ($email_b) email address is considered valid.";
}
?>
It's simple, effective and reliable.
The comment from symcbean is worth adding to this answer as it isn't missed:
The best way to validate an email is to send an email to the address with a link containing a one time pssword. This is just a quick regex check. It does not the domain exists. It does not check the domain has an MX record. It does not check the MTA is accepting mail. It does not check that the mailbox is accepted. It does not check the email is deliverable....
$email_a = 'joe@example.com';
$email_b = 'bogus';
if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
echo "This ($email_a) email address is considered valid.";
}
if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
echo "This ($email_b) email address is considered valid.";
}
Straight from the PHP manual, first hit on Google when searching for php validate email
.
you can use filter_input() method , see documentation
example
if(!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL))
{
echo "E-Mail is not valid";
}
else
{
echo "E-Mail is valid";
}