ballhogjoni Posted May 2, 2008 Share Posted May 2, 2008 Hey all, I am creating a validation for the domain of an email address. The first problem I have is that I am running localhost on my windows comp so checkdnsrr() won't work during testing. So I have used some third party code via the net to validate while testing. I try to test it for real emails and fake emails, but both return false. Can some one help me with understanding and a solution to my problem? Here is my code: This code initiates the function below it: if (checkTheDomainValidity($_POST['email']) == FALSE) { $errorMessage = "<br>There are errors with the form:<br><br>"; $this->set('errorMessage', $errorMessage); $isValidEmail = "Sorry, your email address is not valid"; $this->set('isValidEmail', $isValidEmail); $this->set('postedEmail',$_POST['email']); $this->set('postedEmailConf',$_POST['email_conf']); } else { //continue and write the data to the db echo "good email address"; } This is the function that I got from third parties, its supposed to work on windows: list($userName, $mailDomain) = split("@", $_POST['email']); function checkTheDomainValidity($mailDomain) { $recType = ''; if(!empty($mailDomain)) { if( $recType == '' ) $recType = "MX"; exec("nslookup -type=$recType $mailDomain", $result); // check each line to find the one that starts with the host // name. If it exists then the function succeeded. foreach ($result as $line) { if(eregi("^$mailDomain",$line)) { return TRUE; } } // otherwise there was no mail handler for the domain return FALSE; } return FALSE; } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 2, 2008 Share Posted May 2, 2008 you are passing the full email to the function. this code snippet: list($userName, $mailDomain) = split("@", $_POST['email']); needs to either be included in the function or used in your code where you call the function: <?php list($userName, $mailDomain) = split("@", $_POST['email']); if (checkTheDomainValidity($mailDomain) == FALSE) { $errorMessage = "<br>There are errors with the form:<br><br>"; $this->set('errorMessage', $errorMessage); $isValidEmail = "Sorry, your email address is not valid"; $this->set('isValidEmail', $isValidEmail); $this->set('postedEmail',$_POST['email']); $this->set('postedEmailConf',$_POST['email_conf']); } else { //continue and write the data to the db echo "good email address"; } ?> Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted May 2, 2008 Author Share Posted May 2, 2008 Thanks rhodesa 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.