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; } Link to comment https://forums.phpfreaks.com/topic/103877-solved-mx-email-validation/ 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/103877-solved-mx-email-validation/#findComment-531732 Share on other sites More sharing options...
ballhogjoni Posted May 2, 2008 Author Share Posted May 2, 2008 Thanks rhodesa Link to comment https://forums.phpfreaks.com/topic/103877-solved-mx-email-validation/#findComment-531738 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.