Back to Top

Check Email address using Network Functions

Check Email address using Network Functions

Today we are going back to basics of PHP with a quick tutorial on how to check email address using network functions of PHP.Network functions are the core part of PHP and most of are not using this functions so most of from us are not aware of those function which are very useful.

Here,I am going to show one function which check email address valid or not using a network function.This something interesting right?

So, let’s understand the function and how we can use network functions.First of all ,it checks if the email address format is correct, then looks up and prints the mx records.

For example, if user enter testttttt.com, and the domain does not exist, getmxrr() returns falses and the returned mxhosts array is empty

In the function,I have used checkdnsrr function which Check DNS records corresponding to a provided Internet host name or IP address.

Functions to check Email Address

function CheckMail($Email,$Debug=false)
{
	$Return = false;
	if(!filter_var($Email, FILTER_VALIDATE_EMAIL)) {
		echo "Email address is not valid";
		$Return ='false';
		return $Return;
	}
	list ( $Username, $Domain ) = explode ("@",$Email);
	if ( checkdnsrr ( $Domain, "MX" ) )
	{
		if($Debug) 
			echo "Confirmation : MX record about {$Domain} exists.
"; if ( getmxrr ($Domain, $MXHost)) { for ( $i = 0,$j = 1; $i < count ( $MXHost ); $i++,$j++ ) { // check for gmail email address if(preg_match("/google/i",$MXHost[$i])) { echo "Email address is of Gmail"; $Return = 'true'; return $Return; } else{ echo "Email address is valid"; $Return = 'true'; return $Return; } if($Debug) { echo "Result($j) - $MXHost[$i]
"; } } if($Return == 'false' && count ( $MXHost ) > 0) $Return = true; } $ConnectAddress = $MXHost[0]; } else { echo "Email address is not valid"; $Return=false; //if ($Debug) echo "Can not connect E-Mail server ({$ConnectAddress}).
"; return $Return; } }

You just need to call the function and you can do changes in function as per your requirement.

A big thank you for reading and feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

To Swap Database Row in PHP

Posted on 7 years ago

Bhumi

Learn about the Docker and how it works

Posted on 3 years ago

Bhumi

MySQL FULLTEXT Index and Search

Posted on 3 years ago

Bhumi

How to set a Cookie in PHP

Posted on 7 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 3 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 4 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 5 years ago

Bhumi