Jump to content

[SOLVED] MX email validation


ballhogjoni

Recommended Posts

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

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";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.