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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.