phpbar.de logo

Mailinglisten-Archive

[php] Check eines Pop-Accounts

[php] Check eines Pop-Accounts

Alexander Hessenkamp php_(at)_phpcenter.de
Tue, 14 Aug 2001 16:45:14 +0200


hy Martin,

Am 14 August 2001 um 14:42 schrieben Sie:

PM> Hi, ich habe einmal gehoert, dass man eine e-mail-Adresse daraufhin checken
PM> kann, ob es den pop-server gibt und auf dem Server den angegebenen
PM> account-namen. Weiss jemand, wie man das macht?

PM> Danke! Martin

habe mir vorgestern irgendwo das script runtergeladen..
hier isses.. ich hoffe damit kommst Du weiter..

//___________________________________________________________________________-
<?
/* $Id: chk_mail.php3,v 1.10 2001/02/22 14:43:38 ele Exp $ */

/* 
*    check_mail: PHP-function for checking an email-address
*    Copyright (C) 2001  Gabriele Kayser <k_(at)_yser.de>
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
*
*    GPL is found at:
*       http://www.gnu.org/copyleft/gpl.html
*
*    Usage: check_email($email,$HTTP_SERVER_VARS[SERVER_NAME])
*    Returnvalues: array($message,$success,$server_answer)
*                  Message: reason for failure or empty
*                  Success: 0 = failed, no MX-Record for Domain; 
*                          -1 = failed; 
*                           1 = success
*                  Server Answer: only if exists 
*
*
*/

// ------------------------------------------------------------------------
function check_email($email,$sender_domain) {

list ($user, $domain)  = split ( "_(at)_", $email, 2);
$sender = "info_(at)_" .$sender_domain;
$success = -1;
$connect_success = "";
$connect_out = "";
$server_answer = "";

/* returnmessages */
$dns_failed = "Ihre e-Mail Adresse ist nicht korrekt!<br>\nEs konnte kein Mailserver für <font color='#ff0000'><b>$domain</b></font> gefunden werden.<br>\nBitte überprüfen Sie Ihre Eingabe - ggf. setzen Sie sich bitte mit Ihrem Systemadministrator in Verbindung<br>\n";
$connect_failed = "Kein Mailserver für <b>$email</b> erreichbar<br>\nIhre e-Mail Adresse konnte nicht überprüft werden<br>\n";
$helo_failed = "HELO ". $sender_domain ." failed";
$from_failed = "MAIL FROM: ". $sender ." failed";
$rcpt_failed = "Der Benutzer <font color='#ff0000'><b>".$user."</b></font> ist bei <b>$domain unbekannt</b>!<br>\nBitte überprüfen Sie Ihre Eingabe.
";

/* exists mxrr for $domain  */
if (!getmxrr($domain,$mxhosts,$weight)) {
        $message = $dns_failed;
        $success = 0;
} else {
        $i = 0; /* order mxhosts by weightness */
        while ($i < sizeof($mxhosts)) {
                $hosts[$weight[$i]][$i] = $mxhosts[$i];
//              print "<!-- $i: $weight[$i] * $mxhosts[$i] -->\n";flush();
                $i++;
        }
        ksort($hosts);
        $h = 0;
        $i = 0;
        while (list($key,$value) = each($hosts)) {
                $mxhosts[$i] = $value;
                $weight[$i] = $key;
                while (list($key_name,$hostname) = each($mxhosts[$i])) {
//                       print "<!-- $i-$h: $key_name: $weight[$i] * $hostname -->\n";flush();
                         $mx_sorted[$h] = $hostname;
                         $weight_sorted[$h] = $weight[$i]; 
                         $h++;
                }
                $i++;
        }
        $mxhosts = $mx_sorted;
        $weight = $weight_sorted;
        unset($weight_sorted);
        unset($mx_sorted);
        unset($hosts);            /* end order mxhosts by weightness */

/* connect */
        for ($i = 0; ($i < count ($mxhosts) && $connect_success <> 1); $i++) {
          $smtp_socket = fsockopen ($mxhosts[$i], 25);
          print "<!-- Ask-$i: $mxhosts[$i] * $weight[$i] -->\n";flush();
          /* SMTP-Socket open */
          if ($smtp_socket) { /* ----------------------------------------------- SMTP-Socket */
                        print "<!-- Socket $smtp_socket open -->\n";flush();
                        $s = 0; 
                        $c = 0; 
                        $out =  ""; 
                        socket_set_blocking ($smtp_socket, false); 
                        do { 
                                $out = fgets ($smtp_socket, 2500); 
                                if (ereg ( "^220", $out)) { 
                                        print "<!-- S:$s C:$c OUT: $out -->\n";flush();
                                        $connect_out = $out;
                                        $s = 0; 
                                        $out =  ""; 
                                        $c++; 
                                 } elseif (($c > 0) && ($out ==  "")) { 
                                        break; 
                                 } else { 
                                        $s++; 
                                 } 
                                 if ($s == 99999) { 
                                        break; 
                                 } 
                        } while ($out ==  ""); 

                        if (!ereg("^220",$connect_out)) { 
                                print "<!-- No Connection to $mxhosts[$i] ($connect_out) -->\n"; flush();
                                $message = $connect_failed;
                                $server_answer = htmlentities($connect_out);
                                fclose($smtp_socket);
                        } else {                /* start communication ---------------------------------- HELO */
                                $connect_success = 1;
                                socket_set_blocking ($smtp_socket, true);
                                $helo_success = 0;
                                fputs ($smtp_socket,  "HELO $sender_domain\r\n"); 
                                $z = 0;
                                $helo_output = fgets ($smtp_socket, 2000); 
                                if (ereg("^250",$helo_output)) { $helo_success = 1; } 
                                        print "<!-- $z: HELO SENT: $sender_domain -->\n";flush();
                                        print "<!-- $z: HELO GET: $helo_output -->\n";flush();
                                        socket_set_blocking ($smtp_socket, false); 
                                        do {
                                                $helo_output = fgets ($smtp_socket, 2000);
                                                $z++;
                                                print "<!-- $z: HELO GET: $helo_output -->\n";flush();
                                                if ($z > 10) { break; }
                                        } while (ereg("^[a-zA-Z0-9]",$helo_output)); /* ------------ end HELO */
                                        socket_set_blocking ($smtp_socket, true);

                                        if ($helo_success == 1) { /* ------------- helo_success =>  MAIL FROM */
                                                fputs ($smtp_socket,"MAIL FROM: <". $sender .">\r\n");
                                                $from_output = fgets ($smtp_socket, 2000);
                                                print "<!-- MAIL FROM SENT: <$sender> -->\n";flush();
                                                print "<!-- MAIL FROM GET: $from_output -->\n";flush();
                                                if (ereg("^250",$from_output)) { /* from_success => RCPT TO */
                                                        fputs ($smtp_socket,  "RCPT TO: <$email>\r\n");
                                                        $rcpt_output = fgets ($smtp_socket, 2000);
                                                        print "<!-- RCPT TO SENT: <$email> -->\n"; flush();
                                                        print "<!-- RCPT TO GET: ". htmlentities($rcpt_output) ." -->\n";flush();
                                                        if (ereg("^250",$rcpt_output)) {
                                                                $success = 1;
                                                                $message = "";
                                                        } else {
                                                                $message = $rcpt_failed;
                                                                $server_answer = htmlentities($rcpt_output);
                                                        }
                                                } else { /* ---------------------- end from_success RCPT TO */
                                                        $message = $from_failed;
                                                        $server_answer = htmlentities($from_output);
                                                } /* end if (ereg("^250",$from_output) ------------- MAIL FROM */

                                } else {
                                        $message = $helo_failed;
                                        $server_answer = htmlentities($helo_output);
                                } /* end if $helo_success */

                        } /* end if ^220 $connect_out */
                        print "<!-- Send: QUIT -->\n";
                        fputs($smtp_socket,"QUIT\r\n");
                        print "<!-- Close $smtp_socket -->\n";
                        fclose($smtp_socket);
          } /* end if smtp_socket open ----------------------------------------- SMTP-Socket */

        } /* end for connect $mxhosts[$i] */

} /* end exists mxrr for $domain  */

return array($message,$success,$server_answer);
}

?>

//-------------------------------------------
hoffe das hilft
ciao
Alex

                         mailto:andiamo_(at)_hessenkamp.de




php::bar PHP Wiki   -   Listenarchive