Email Code

  Home arrow Email Code arrow Checking if Email address is deliverab...
EMAIL CODE

Checking if Email address is deliverable
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2002-06-17

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    SMPT protocol check of email address at preferred MX host or host.

    This returns nothing if email is valid, or a nice descriptive error message. It will split out the domain, lookup the preferred mailhost, connect to it an try to deliver at the given address. If no MX record is found it will try to deliver directly at the SMTP port. Since most mailservers say that the given address has valid syntax the only more waterproof check would be to send mail and wait for a reply.



    This is the fullest implementation

    By : datasmid

    <?php

    function checkemail($email){
    list($mailbox,$domain) = split('@',$email,2);
    $state = 'domain';

    // find preferred mailserver
    if(getmxrr($domain,$mailhosts,$pref)){
    asort($pref);
    foreach($pref as $preferred){
    $mailserver = $mailhosts[key($pref)];
    break;
    }
    $state = "trying mailserver $mailserver";
    $state = mailconnect($mailserver,$email);
    }else{
    // no mail exchange found try as host
    $state = "No MX, trying $domain";
    $state = mailconnect($domain,$email);
    }
    return $state;
    }

    function mailconnect($mailserver,$email){
    $myhostname = $SERVER_NAME;
    $connection = fsockopen($mailserver, 25);
    if($connection){
    $state = "connected to $mailserver";
    // Nothing to do with greeting
    //$smtpgreeting = fread($connection, 512);

    //if($smtpgreeting){
    fputs($connection, "HELO $myhostname\r\n");
    $hello = fgets($connection, 512);
    if($hello){
    $state = "chatting to $mailserver: $hello";
    fputs($connection, "MAIL FROM: <webserver@$myhostname>\r\n");
    $youok = fgets($connection, 512);
    if($youok){
    $state = "chatting to $mailserver: $youok";
    fputs($connection, "RCPT TO: <$newaddress>\r\n");
    $recepient = fgets($connection, 512);
    $state = "chatting to $mailserver: $recepient";
    if(ereg('250',$recepient)){
    fputs($connection, "QUIT\r\n");
    $deliverable = true;
    $state = false;
    }elseif(ereg('220',$recepient)){
    fputs($connection, "QUIT\r\n");
    $deliverable = true;
    $state = false;
    }else{
    $deliverable = false;
    $state = "RCPT? $recepient $newaddress";
    }
    }
    }else{
    $state = "$mailserver not accepting mail now, please try again.";
    }
    //}else{
    //$state = 'mailserver not greeting me';
    //break;
    //}
    }else{
    $state = "$mailserver not listening";
    }
    return $state;
    }
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Email Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    EMAIL CODE ARTICLES

    - Basic Ajax contact form
    - Random validation image
    - tinySendMail
    - SaferMail 0.7
    - Smtp Auth Email Script
    - Search Mime Email Structure
    - PHP Text / HTML Email with Attachments 2.1
    - Simple way to send mail wih one attached Doc...
    - Generic POP3 Class
    - PHP Text / HTML Email with Unlimited Attachm...
    - Another SendMail
    - email with attachment
    - Get Email Addresses from Strings
    - EmailCode
    - Email Validation - Gone Wild

    Developer Shed Affiliates

     



    © 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap