TO Check The Given Email Exist In a domain

Discussion in 'Programming' started by girishbm.gowda, Jan 28, 2010.

  1. #1
    Hi,

    I want to implement the following in my web page

    in sign up we will ask to enter user existing email id , so now i need to check weather the entered email currently available are not without sending any confirmation mail

    can any body help me to write php script r code , atleast few examples on this one

    Thanks In advance

    regard's
    girish
    girish@pbminfotech.com
     
    girishbm.gowda, Jan 28, 2010 IP
  2. wineri.es

    wineri.es Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Only one way: Send email to this address. If it bounced back with delivery error - it means does not exist.
     
    wineri.es, Jan 28, 2010 IP
  3. girishbm.gowda

    girishbm.gowda Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    that is also one option but it is quit common n it takes time......

    can u tell me any other which we can implement like domain check can we implement same for mail check
     
    girishbm.gowda, Jan 28, 2010 IP
  4. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
  5. girishbm.gowda

    girishbm.gowda Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hi please find the below attachment i am getting the following error

    Warning: fsockopen() [function.fsockopen]: unable to connect to pbminfotech.com:25 (Connection timed out) in /home/pbminfot/public_html/girish/test/giri.class.php on line 70
    try pbminfotech.com:25
    Warning: fsockopen() [function.fsockopen]: unable to connect to pbminfotech.com:25 (Connection timed out) in /home/pbminfot/public_html/girish/test/giri.class.php on line 70
    bool(false) gbm@pbminfotech.com is invalid

    //-------------My code in index.php----------------------//
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    <form method="post">
    <div>
    <input type="text" name="email123" /> <input type="submit" name="checkMail" value="Search Mail"/>
    <?php
    include("giri.class.php");
    /* if(isset($_POST['checkMail'])){
    echo $Email = $_POST['email'].'User Mail'.'<br/>';
    //echo $temp_email = split("@", $Email);
    list ($Email, $domain) = split("@", $Email);
    //echo $Email;
    // echo $domain;
    if (! checkdnsrr($domain, "MX")) {
    //die('E-mail does not exist')
    echo "E-mail does not exist";
    }else {
    $array = array($Email, $domain);
    echo $array[0];
    $Email = implode("@", $array);
    }
    } */
    /* if(isset($_POST['checkMail'])){
    $email = $_POST['email123'];
    //function validate_email($email){
    //echo $email;
    //$exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";

    // if(eregi($exp,$email)){

    if(checkdnsrr(array_pop(explode("@",$email)),"MX")){
    //return true;
    echo "Valid";
    }else{
    //return false;
    echo "Invalid";
    }

    // }else{

    // return false;

    // }
    //}
    } */

    //-------------------------------------------------------------//
    if(isset($_POST['checkMail'])){

    $tedu = $_POST['email123'];


    // the email to validate
    $email = $tedu;
    // an optional sender
    $sender = 'info@expertcore.org';
    // instantiate the class
    $SMTP_Valid = new SMTP_validateEmail();
    // turn debugging on to view the SMTP session
    $SMTP_Valid->debug = true;
    // do the validation
    $result = $SMTP_Valid->validate($email, $sender);
    // view results
    var_dump($result);
    echo $email.' is '.($result ? 'valid' : 'invalid')."\n";

    // send email?
    if ($result) {
    //mail(...);
    }

    //-------------------------------------------------------------//
    }//end of submit
    ?>
    </div>
    </form>
    </body>
    </html>

    //-------------End of code in index.php----------------------//

    //-------------My code in giri.class.php---------------------//
    <?php
    /**
    * Validate an Email Address Via SMTP
    * This queries the SMTP server to see if the email address is accepted.
    * @copyright http://creativecommons.org/licenses/by/2.0/ - Please keep this comment intact
    * @author gabe@fijiwebdesign.com
    * @version 0.1a
    */
    class SMTP_validateEmail {

    var $sock;

    var $user;
    var $domain;
    var $port = 25;
    var $max_conn_time = 30;
    var $max_read_time = 5;

    var $from_user = 'user';
    var $from_domain = 'localhost';

    var $debug = false;

    function SMTP_validateEmail($email = false, $sender = false) {
    if ($email) {
    $this->setEmail($email);
    }
    if ($sender) {
    $this->setSenderEmail($sender);
    }
    }

    function setEmail($email) {
    list($user, $domain) = explode('@', $email);
    $this->user = $user;
    $this->domain = $domain;
    }

    function setSenderEmail($email) {
    list($user, $domain) = explode('@', $email);
    $this->from_user = $user;
    $this->from_domain = $domain;
    }

    /**
    * Validate an Email Address
    * @param String $email Email to validate (recipient email)
    * @param String $sender Senders Email
    */
    function validate($email = false, $sender = false) {
    if ($email) {
    $this->setEmail($email);
    }
    if ($sender) {
    $this->setSenderEmail($sender);
    }
    // retrieve SMTP Server via MX query on domain
    $result = getmxrr($this->domain, $hosts);
    // last fallback is the original domain
    array_push($hosts, $this->domain);

    $this->debug(print_r($hosts,1 ));

    $timeout = $this->max_conn_time/count($hosts);

    // try each host
    foreach($hosts as $host) {
    // connect to SMTP server
    $this->debug("try $host:$this->port\n");
    if ($this->sock = fsockopen($host, $this->port, $errno, $errstr, (float) $timeout)) {
    socket_set_blocking($this->sock, false);
    break;
    }
    }

    // did we get a TCP socket
    if ($this->sock) {
    // say helo
    $this->send("HELO ".$this->from_domain);
    // tell of sender
    $this->send("MAIL FROM: <".$this->from_user.'@'.$this->from_domain.">");
    // ask of recepient
    $reply = $this->send("RCPT TO: <".$this->user.'@'.$this->domain.">");
    // quit
    $this->send("quit");
    // close socket
    fclose($this->sock);
    // get code and msg from response
    list($code, $msg) = explode(' ', $reply);

    if ($code == '250') {
    // you received 250 so the email address was accepted
    return true;
    }

    }

    return false;
    }


    function send($msg) {
    fwrite($this->sock, $msg."\n");
    $resp = '';
    $start = $this->microtime_float();
    while(1) {
    $reply = fread($this->sock, 2082);
    $resp .= $reply;
    if (($resp != '' && trim($reply) == '')
    || ($this->microtime_float() - $start > $this->max_read_time )) {
    break;
    }
    }

    $this->debug(">>>\n$msg\n");
    $this->debug("<<<\n$resp");

    return $resp;
    }

    /**
    * Simple function to replicate PHP 5 behaviour. http://php.net/microtime
    */
    function microtime_float() {
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
    }

    function debug($str) {
    if ($this->debug) {
    echo $str;
    }
    }
    }
    ?>
    //-------------End of code in giri.class.php---------------------//
     

    Attached Files:

    girishbm.gowda, Jan 29, 2010 IP
  6. girishbm.gowda

    girishbm.gowda Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Please Clear me The Following Details
    var $user;
    var $domain;
    var $port = 25;
    var $max_conn_time = 30;
    var $max_read_time = 5;
    var $from_user = 'user';
    var $from_domain = 'localhost';
    var $debug = false;

    is that port no will be changed frequently?
    user should be the control panel details?

    as i am getting the following errors

    Array ( [0] => pbminfotech.com [1] => pbminfotech.com ) try pbminfotech.com:25
    Warning: fsockopen() [function.fsockopen]: unable to connect to pbminfotech.com:25 (Connection timed out) in /home/pbminfot/public_html/girish/test/giri.class.php on line 70
    try pbminfotech.com:25
    Warning: fsockopen() [function.fsockopen]: unable to connect to pbminfotech.com:25 (Connection timed out) in /home/pbminfot/public_html/girish/test/giri.class.php on line 70
    bool(false) gbm@pbminfotech.com is invalid
     
    girishbm.gowda, Jan 29, 2010 IP
  7. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    NeoCambell, Jan 29, 2010 IP