smtp email validation

Javascript, PHP One response so far

SMTP is a core Internet protocol used to transfer e-mail messages between servers (first defined in RFC 821 in 1982). This contrasts with protocols such as POP3 and IMAP, which are used by messaging clients to retrieve e-mail. SMTP servers look at the destination address of a message and contact the target mail server directly. SMTP was designed to be a reliable message delivery system. Reliable in this case means that a message handled by SMTP is intended to get to its destination or generate an error message accordingly.

Email Syntax can check whether an email address has a valid format(by using regular expression), however, in order to check if the email address actually exists, you will have to query the email domain for the existence of the email address.

The PHP class encapsulates the SMTP transation between the remote domain, as well as the DNS lookup for the Mail Transfer Agent (MTA) responsible for that domain.

The class can take a number of email addresses, and return whether they are valid or not. It will group together emails with the same domain, and create a single SMTP connection to the MTA for those emails for efficiency.

This class is meant to be a secondary validation of an email address after the email syntax is validated. It can also provide intermediate email validation before sending a confirmation email to the email address, which does not provide user feedback if the email is invalid – and thus loss of users.

 Note: smtp email validation only works if smtp port is open.Generally hosting companies keep this port closed on account of some security you may have to ask hosting company to open the smtp port.
Below is the frontend code for smtp validation.
<br />
&lt;script src=&quot;;&gt;&lt;/script&gt;<br />
&lt;script type=&quot;text/javascript&quot;&gt;<br />
function emailcheck()<br />
{<br />
 $.post(&quot;check.php&quot;,{ email:$('#email').val(),rand:Math.random() } ,function(data)<br />
 {<br />
 if(data=='valid')<br />
document.getElementById('message').innerHTML=&quot;Email Address is Valid&quot;;}<br />
 else<br />
 document.getElementById('message').innerHTML=&quot;Email Address is Invalid&quot;;</p>
<p> });<br />
<p>&lt;/script&gt;<br />
&lt;form name=&quot;form1&quot; action=&quot;congrats.php&quot; method=&quot;post&quot;&gt;<br />
&lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot;&gt;<br />
&lt;input type=&quot;button&quot; value=&quot;Submit&quot; onClick=&quot;return emailcheck();&quot; &gt;<br />
&lt;/form&gt;<br />
&lt;span id=&quot;message&quot;&gt;&lt;/div&gt;<br />

Below is the code for check.php
<br />
&lt;?php&lt;/div&gt;<br />
// include SMTP Email Validation Class<br />
<p>// the email to validate<br />
$email = $_POST['email'];<br />
// an optional sender<br />
$sender = $_POST['email'];<br />
// instantiate the class<br />
$SMTP_Validator = new SMTP_validateEmail();<br />
// turn on debugging if you want to view the SMTP transaction<br />
$SMTP_Validator-&gt;debug = true;<br />
// do the validation<br />
$results = $SMTP_Validator-&gt;validate(array($email), $sender);<br />
echo ($results[$email] ? 'valid' : 'invalid');</p>

Here is the link to download the above php class file: [highlight]smtp_validateEmail.class[/highlight]

The following two tabs change content below.
I am a core php developer and web designer working as a freelancer in elance,odesk etc.

Latest posts by Mudit (see all)

  • DNeers

    Awesome post!!! I guess it’s provides Reliable and efficient communication really fantastic, thank you for this awareness.