Menu

How to Validate eMail ID in PHP

PHP, Tech-Byte By Apr 23, 2013 1 Comment


Many times we use to get the user’s mail id in our form. Through the regex we just check the entered style of mail id. Mail id having @ or not or having any tld or not and all. But is it really a validation of mail id ? I think no validation means that the mail id and tld are really exists or not. let me tell you how you can validate the mail id. Use the below code to validate the mail id.

<?php

function domain_exists($email, $record = 'MX'){

list($user, $domain) = explode('@', $email);

return checkdnsrr($domain, $record);

}

if(domain_exists('vivek@simplyitsols.com')) {

echo('This MX records exists; I will accept this email as valid.');

}

else {

echo('No MX record exists;  Invalid email.');

}

?>

Author

Hello i am Vivek Moyal PHP developer and writes tutorials for students and beginners. Love to explore new cities

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *