dyr Posted March 4, 2012 Share Posted March 4, 2012 Hi all, I'm trying to add a section where it verifies that the email address is active in my register code. My code below is it checking the dnsrr, and if it is not real, I have it die and an error message appears. However, I am getting the error message all the time, whether I am sure the email is working or not. First I declared my email variable ($email), and then after the code below I of course insert the new data in to the database. I'm doing this over my localhost, so is that why it can't verify emails? Or am I setting this up wrong? <?php $email = trim($_POST['email']); if (False !== strpos($email, '@')) die("Please type in an email address.<br><br><a href=register.php>Continue</a>"); if(!@checkdnsrr($mailDomain,'MX')) die("Not real email address. Please try again.<br><br> <a href=register.php>Continue</a>"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/258219-verify-email-not-working/ Share on other sites More sharing options...
litebearer Posted March 4, 2012 Share Posted March 4, 2012 might look into http://www.electrictoolbox.com/php-email-validation-filter-var-updated/ Quote Link to comment https://forums.phpfreaks.com/topic/258219-verify-email-not-working/#findComment-1323624 Share on other sites More sharing options...
dyr Posted March 4, 2012 Author Share Posted March 4, 2012 might look into http://www.electrictoolbox.com/php-email-validation-filter-var-updated/ Ah, I see. So how would I set this up similar to my example above (making an if false, die function)? <?php function validateEmailAddress($email) { if return filter_var(!$email, FILTER_VALIDATE_EMAIL) && preg_match('/@.+\./', $email); } die("That email address does not exist."); ?> Code above doesn't work, but had to give it my best shot at trying to negate it. Quote Link to comment https://forums.phpfreaks.com/topic/258219-verify-email-not-working/#findComment-1323630 Share on other sites More sharing options...
litebearer Posted March 4, 2012 Share Posted March 4, 2012 Try... function validateEmailAddress($email) { return filter_var($email, FILTER_VALIDATE_EMAIL) && preg_match('/@.+\./', $email); } if(validateEmailAddress($email) !=1) { echo "That email address does not exist."l exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/258219-verify-email-not-working/#findComment-1323637 Share on other sites More sharing options...
dyr Posted March 4, 2012 Author Share Posted March 4, 2012 Thanks for clearing that up! Didn't think to use a !=1 option! It checks to see if there is a @ and ., however does not actually verify that the email exists (for example, it let me register using [email protected]). Am I just not understanding the code correctly? Quote Link to comment https://forums.phpfreaks.com/topic/258219-verify-email-not-working/#findComment-1323642 Share on other sites More sharing options...
litebearer Posted March 4, 2012 Share Posted March 4, 2012 validating the syntax/format of an address is different from validating the actual existence of the address. Consider if hosts allowed simple validation how much greater the spamming would become. Best way to validate is send and email asking user to verify. Quote Link to comment https://forums.phpfreaks.com/topic/258219-verify-email-not-working/#findComment-1323645 Share on other sites More sharing options...
dyr Posted March 4, 2012 Author Share Posted March 4, 2012 Email confirmation looks a tad too complicated for me to understand right now. Oh well, thanks again for your help and explanations! Quote Link to comment https://forums.phpfreaks.com/topic/258219-verify-email-not-working/#findComment-1323665 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.