Kodları lütfen aşağıdaki butonları kullanarak renklendirin. Örnek: <php> echo "Selam Dünya"; </php>
Yardım
karakter kaldı

php ile mail kontrolu

elimde kalabalık bir mail list var daha uzun zamandan beri elimde bulunan bir mail listesi ve bu mail adreslerinin nekadarının geçerli olduğunu öğrenmem gerekiyor bunu nasıl yapabilirim bunun bir api si varmı bildiğiniz yada bir mail atıp geri dönen mailleri nasıl kontrol ederim smtp ile falan

spesifik domaine ait mailleri (mail@herhangidomain.com) domainine dns ve mx sorgusu yaparak eleyebilirim ama hotmail yahoo gmail gibi servislerinkine ne yapabilirim bi fikri olan varsa şimdiden teşekkür ederim

sistem olarak php kullanıcam
+0
-0
Cevaba KatılıyorumKatılmıyorum
Cevap Yaz Yorum Yaz Arşivime Ekle Takip Et

Cevaplar

  • pialfa adlı üyenin fotoğrafı
    10 yıl önce yazılmış
    11 cevap - 43 soru
    <?php

    class SMTP_validateEmail {

    /**
    * PHP Socket resource to remote MTA
    * @var resource $sock
    */
    var $sock;

    /**
    * Current User being validated
    */
    var $user;
    /**
    * Current domain where user is being validated
    */
    var $domain;
    /**
    * List of domains to validate users on
    */
    var $domains;
    /**
    * SMTP Port
    */
    var $port = 25;
    /**
    * Maximum Connection Time to an MTA
    */
    var $max_conn_time = 30;
    /**
    * Maximum time to read from socket
    */
    var $max_read_time = 5;

    /**
    * username of sender
    */
    var $from_user = 'user';
    /**
    * Host Name of sender
    */
    var $from_domain = 'localhost';

    /**
    * Nameservers to use when make DNS query for MX entries
    * @var Array $nameservers
    */
    var $nameservers = array(
    '192.168.0.1'
    );

    var $debug = false;

    /**
    * Initializes the Class
    * @return SMTP_validateEmail Instance
    * @param $email Array[optional] List of Emails to Validate
    * @param $sender String[optional] Email of validator
    */
    function SMTP_validateEmail($emails = false, $sender = false) {
    if ($emails) {
    $this->setEmails($emails);
    }
    if ($sender) {
    $this->setSenderEmail($sender);
    }
    }

    function _parseEmail($email) {
    $parts = explode('@', $email);
    $domain = array_pop($parts);
    $user= implode('@', $parts);
    return array($user, $domain);
    }

    /**
    * Set the Emails to validate
    * @param $emails Array List of Emails
    */
    function setEmails($emails) {
    foreach($emails as $email) {
    list($user, $domain) = $this->_parseEmail($email);
    if (!isset($this->domains[$domain])) {
    $this->domains[$domain] = array();
    }
    $this->domains[$domain][] = $user;
    }
    }

    /**
    * Set the Email of the sender/validator
    * @param $email String
    */
    function setSenderEmail($email) {
    $parts = $this->_parseEmail($email);
    $this->from_user = $parts[0];
    $this->from_domain = $parts[1];
    }

    /**
    * Validate Email Addresses
    * @param String $emails Emails to validate (recipient emails)
    * @param String $sender Sender's Email
    * @return Array Associative List of Emails and their validation results
    */
    function validate($emails = false, $sender = false) {

    $results = array();

    if ($emails) {
    $this->setEmails($emails);
    }
    if ($sender) {
    $this->setSenderEmail($sender);
    }

    // query the MTAs on each Domain
    foreach($this->domains as $domain=>$users) {

    $mxs = array();

    // retrieve SMTP Server via MX query on domain
    list($hosts, $mxweights) = $this->queryMX($domain);

    // retrieve MX priorities
    for($n=0; $n < count($hosts); $n++){
    $mxs[$hosts[$n]] = $mxweights[$n];
    }
    asort($mxs);

    // last fallback is the original domain
    array_push($mxs, $this->domain);

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

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

    // try each host
    while(list($host) = each($mxs)) {
    // connect to SMTP server
    $this->debug("try $host:$this->port\n");
    if ($this->sock = fsockopen($host, $this->port, $errno, $errstr, (float) $timeout)) {
    stream_set_timeout($this->sock, $this->max_read_time);
    break;
    }
    }

    // did we get a TCP socket
    if ($this->sock) {
    $reply = fread($this->sock, 2082);
    $this->debug("<<<\n$reply");

    preg_match('/^([0-9]{3}) /ims', $reply, $matches);
    $code = isset($matches[1]) ? $matches[1] : '';

    if($code != '220') {
    // MTA gave an error...
    foreach($users as $user) {
    $results[$user.'@'.$domain] = false;
    }
    continue;
    }

    // say helo
    $this->send("HELO ".$this->from_domain);
    // tell of sender
    $this->send("MAIL FROM: <".$this->from_user.'@'.$this->from_domain.">");

    // ask for each recepient on this domain
    foreach($users as $user) {

    // ask of recepient
    $reply = $this->send("RCPT TO: <".$user.'@'.$domain.">");

    // get code and msg from response
    preg_match('/^([0-9]{3}) /ims', $reply, $matches);
    $code = isset($matches[1]) ? $matches[1] : '';

    if ($code == '250') {
    // you received 250 so the email address was accepted
    $results[$user.'@'.$domain] = true;
    } elseif ($code == '451' || $code == '452') {
    // you received 451 so the email address was greylisted (or some temporary error occured on the MTA) - so assume is ok
    $results[$user.'@'.$domain] = true;
    } else {
    $results[$user.'@'.$domain] = false;
    }

    }

    // quit
    $this->send("quit");
    // close socket
    fclose($this->sock);

    }
    }
    return $results;
    }


    function send($msg) {
    fwrite($this->sock, $msg."\r\n");

    $reply = fread($this->sock, 2082);

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

    return $reply;
    }

    /**
    * Query DNS server for MX entries
    * @return
    */
    function queryMX($domain) {
    $hosts = array();
    $mxweights = array();
    if (function_exists('getmxrr')) {
    getmxrr($domain, $hosts, $mxweights);
    } else {
    // windows, we need Net_DNS
    require_once 'Net/DNS.php';

    $resolver = new Net_DNS_Resolver();
    $resolver->debug = $this->debug;
    // nameservers to query
    $resolver->nameservers = $this->nameservers;
    $resp = $resolver->query($domain, 'MX');
    if ($resp) {
    foreach($resp->answer as $answer) {
    $hosts[] = $answer->exchange;
    $mxweights[] = $answer->preference;
    }
    }

    }
    return array($hosts, $mxweights);
    }

    /**
    * 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 htmlentities($str);
    }
    }

    }


    ?>

    KULLANIMI :

    < ?php

    // the email to validate
    $email = 'joe@gmail.com';
    // an optional sender
    $sender = 'user@example.com';
    // instantiate the class
    $SMTP_Valid = new SMTP_validateEmail();
    // 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(...);
    }

    ?>
    • emoty_88 adlı üyenin fotoğrafı emoty_88
      ilgin için teşekkür ederim en kısa zaman içinde çalışıtırıp geri dönüş yapıcam
      10 yıl önce yazılmış
    • emoty_88 adlı üyenin fotoğrafı emoty_88
      sicripti yeni kontrol etme şansım oldu fakat tam olarak çalışmıyor sanırım iki farklı serverda test ettim birincisinde 220 yetki sorunları döndü fakat tüm maillere valid olarak işaretleri yani yne yazarsam yazayım email adresi doğrudur diye geri döndü (hostin üzerinde)

      birde bir vds üzerinde test ettim yine bir kaç yetki sorunu döndürdü bu seferde @hotmail olanlara yalnız (doğru olanlarada ) diğer domainlere de doğru olarak işaretler
      farklı domain için domain varsada yoksada doğru olarak işaretledi

      vds çıktısı aşağıdaki gibidir eğer bir fikriniz varsa yada tahmin yürüte bilirseniz çok memnun olurum


      Array
      (
      [mx4.hotmail.com] => 5
      [mx1.hotmail.com] => 5
      [mx3.hotmail.com] => 5
      [mx2.hotmail.com] => 5
      [0] =>
      )

      try mx4.hotmail.com:25

      <<<
      220 snt0-mc4-f16.Snt0.hotmail.com Sending unsolicited commercial or bulk e-mail to Microsoft's computer network is prohibited. Other restrictions are found at http://privacy.msn.com/Anti-spam/. Violations will result in use of equipment located in California and other states. Sat, 10 Sep 2011 01:02:33 -0700

      >>>
      HELO gmail.com

      <<<
      250 snt0-mc4-f16.Snt0.hotmail.com (3.13.0.93) Hello [80.86.91.9]

      >>>
      MAIL FROM: <emoty88@gmail.com>

      <<<
      250 emoty88@gmail.com....Sender OK

      >>>
      RCPT TO: <emoy_88@hotmail.com>

      <<<
      550 Requested action not taken: mailbox unavailable

      >>>
      RCPT TO: <emoootrre98@hotmail.com>

      <<<
      550 Requested action not taken: mailbox unavailable

      >>>
      quit

      <<<
      221 snt0-mc4-f16.Snt0.hotmail.com Service closing transmission channel

      Array
      (
      [canerturkmen.com.tr] => 0
      [0] =>
      )

      try canerturkmen.com.tr:25

      <<<
      220-server80.nt119.datacenter.ni.net.tr ESMTP Exim 4.69 #1 Sat, 10 Sep 2011 11:02:37 +0300
      220-We do not authorize the use of this system to transport unsolicited,
      220 and/or bulk e-mail.

      >>>
      HELO gmail.com

      <<<
      250 server80.nt119.datacenter.ni.net.tr Hello euve21565.server4you.net [80.86.91.9]

      >>>
      MAIL FROM: <emoty88@gmail.com>

      <<<
      250 OK

      >>>
      RCPT TO: <mail@canerturkmen.com.tr>

      <<<
      250 Accepted

      >>>
      RCPT TO: <maiksi@canerturkmen.com.tr>

      <<<
      250 Accepted

      >>>
      quit

      <<<
      221 server80.nt119.datacenter.ni.net.tr closing connection

      Array
      (
      [0] =>
      )

      try 0:25

      <<<
      220 euve21565.server4you.net ESMTP Postfix (Debian/GNU)

      >>>
      HELO gmail.com

      <<<
      250 euve21565.server4you.net

      >>>
      MAIL FROM: <emoty88@gmail.com>

      <<<
      250 2.1.0 Ok

      >>>
      RCPT TO: <sd@adbhjskjdjdkjfn.com>

      <<<
      250 2.1.5 Ok

      >>>
      quit

      <<<
      221 2.0.0 Bye

      array(5) {
      ["emoy_88@hotmail.com"]=>
      bool(false)
      ["emoootrre98@hotmail.com"]=>
      bool(false)
      ["mail@canerturkmen.com.tr"]=>
      bool(true)
      ["maiksi@canerturkmen.com.tr"]=>
      bool(true)
      ["sd@adbhjskjdjdkjfn.com"]=>
      bool(true)
      }

      Array is valid

      object(SMTP_validateEmail)#4 (11) {
      ["sock"]=>
      resource(12) of type (Unknown)
      ["user"]=>
      NULL
      ["domain"]=>
      NULL
      ["domains"]=>
      array(3) {
      ["hotmail.com"]=>
      array(2) {
      [0]=>
      string(7) "emoy_88"
      [1]=>
      string(11) "emoootrre98"
      }
      ["canerturkmen.com.tr"]=>
      array(2) {
      [0]=>
      string(4) "mail"
      [1]=>
      string(6) "maiksi"
      }
      ["adbhjskjdjdkjfn.com"]=>
      array(1) {
      [0]=>
      string(2) "sd"
      }
      }
      ["port"]=>
      int(25)
      ["max_conn_time"]=>
      int(30)
      ["max_read_time"]=>
      int(5)
      ["from_user"]=>
      string(7) "emoty88"
      ["from_domain"]=>
      string(9) "gmail.com"
      ["nameservers"]=>
      array(1) {
      [0]=>
      string(14) "208.67.222.222"
      }
      ["debug"]=>
      bool(true)
      }

      buraya geldi
      10 yıl önce yazılmış