NoobLaPHP Posted March 5, 2014 Share Posted March 5, 2014 Ok, i am having a load of people register to a subscription service on my website using invalid emails. I would like to add a function in that can read an email. If the source is right it will continue to process the form. If it's not then it shows an error message. Would i use something like an explode function to seperate using the @ in an email and read the end part(live.co.uk) and then have an array set up to see if the end is in the email or what? Examples would be a great help if you have any other ideas. Thanks Quote Link to comment Share on other sites More sharing options...
Solution NoobLaPHP Posted March 5, 2014 Author Solution Share Posted March 5, 2014 I have found this that seems to work well. function domain_exists( $email, $record = 'MX' ) { list( $user, $domain ) = explode( '@', $email ); return checkdnsrr( $domain, $record ); } if(domain_exists('user@davidwalsh.name')) { echo('This MX records exists; I will accept this email as valid.'); } else { echo('No MX record exists; Invalid email.'); } Source: http://davidwalsh.name/php-email-validator Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted March 5, 2014 Share Posted March 5, 2014 For what it's worth, PHP has a built-in function for validating things like email addresses: http://www.php.net/manual/en/filter.examples.validation.php Quote Link to comment 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.