sphinx Posted November 24, 2011 Share Posted November 24, 2011 Hello, the below validator keeps saying invalid email, can you notice any issues: <form name="input" action="check.php" method="post"> Username: <input type="text" id="email" name="email" /> <input type="submit" value="Submit" /> </form> Check.php <?php if (isset($_REQUEST['email'])) { $email = trim($_POST['email']); if(!checkEmail($email)) { echo 'Invalid email address!'; } else { echo 'Email address is valid'; } } function checkEmail($email) { if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) { list($username,$domain)=split('@',$email); if(!checkdnsrr($domain, 'MX')) { return false; } if(!fsockopen($domain,25,$errno,$errstr,30)) { return false; } return true; } return false; } ?> Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/251751-email-validator-not-operating/ Share on other sites More sharing options...
anups Posted November 25, 2011 Share Posted November 25, 2011 u can use filter_var function for validation $valid_email = filter_var('[email protected]', FILTER_VALIDATE_EMAIL); if($valid_email){ echo "valid"; }else{ echo "In valid"; } Quote Link to comment https://forums.phpfreaks.com/topic/251751-email-validator-not-operating/#findComment-1291076 Share on other sites More sharing options...
sphinx Posted November 25, 2011 Author Share Posted November 25, 2011 I believe the code I submitted actually checks the email validity. Quote Link to comment https://forums.phpfreaks.com/topic/251751-email-validator-not-operating/#findComment-1291140 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.