Konular
Link Değişimi
Php
Mysql
Html
Javascript
Windows Vista
Program Anlatımı
Internet
Google
Windows 2003 Server
Komikler
Windows Xp
Isa Server
Network
Ofis Programları
Css
Photoshop
Donanım
Joomla
Youtube Video
Diğer Konular
Jquery

Linklerimiz
Eskişehir Emlak
Private Yachts Gocek
Oteller Hakkında Yorum
Suggest A Site
5 Yıldız Herşey Dahil Antalya Otelleri
Ucuz Tekne Turu
Ferry Boat to Turkey
Otel Maps
Otel iletişim
Boutique Gulets

 
php smtp mail adresi doğrulama (e-mail address verifier)
Bu class, email adresi
domainın geçerli olup olmadığını ve
email server üzerinde bu email kullanıcısının var olup olmadığını kontrol eder.

class içinde $port=25 olarak atanmıştır.
yahoo,gmail,hotmail,msn gibi email serverlar
farklı portlar kullanabildiğinden porta atanan değeri değiştirmeniz gerekebilir.



smtp_validateEmail.class.php adlı dosyaya aşağıdaki class ı ekleyiniz

<?php

class SMTP_validateEmail {


var $sock;

var $user;

var $domain;

var $domains;

var $port = 25;

var $max_conn_time = 30;

var $max_read_time = 5;

var $from_user = 'user';

var $from_domain = 'localhost';


var $nameservers = array(
'192.168.0.1'
);

var $debug = false;

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);
}


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;
}
}


function setSenderEmail($email) {
$parts = $this->_parseEmail($email);
$this->from_user = $parts[0];
$this->from_domain = $parts[1];
}


function validate($emails = false, $sender = false) {

$results = array();

if ($emails) {
$this->setEmails($emails);
}
if ($sender) {
$this->setSenderEmail($sender);
}
foreach($this->domains as $domain=>$users) {

$mxs = array();
$this->domain = $domain;
list($hosts, $mxweights) = $this->queryMX($domain);
for($n=0; $n < count($hosts); $n++){
$mxs[$hosts[$n]] = $mxweights[$n];
}
asort($mxs);
$mxs[$this->domain] = 0;

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

$timeout = $this->max_conn_time;
while(list($host) = each($mxs)) {
$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;
}
}
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') {
foreach($users as $user) {
$results[$user.'@'.$domain] = false;
}
continue;
}
$this->send("HELO ".$this->from_domain);
$this->send("MAIL FROM: <".$this->from_user.'@'.$this->from_domain.">");
foreach($users as $user) {
$reply = $this->send("RCPT TO: <".$user.'@'.$domain.">");
preg_match('/^([0-9]{3}) /ims', $reply, $matches);
$code = isset($matches[1]) ? $matches[1] : '';

if ($code == '250') {
$results[$user.'@'.$domain] = true;
} elseif ($code == '451' || $code == '452') {
$results[$user.'@'.$domain] = true;
} else {
$results[$user.'@'.$domain] = false;
}

}

// reset before quit
$this->send("RSET");

// 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;
}


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);
}


function microtime_float() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}

function debug($str) {
if ($this->debug) {
echo '<pre>'.htmlentities($str).'</pre>';
}
}

}
?>


örnek sayfa kodu


<?php
require_once('smtp_validateEmail.class.php');

$email = 'info@otelreferans.com';

$sender = 'bpatron@codekodu.com';

$SMTP_Validator = new SMTP_validateEmail();

$SMTP_Validator->debug = true;

$results = $SMTP_Validator->validate(array($email), $sender);

echo $email.' is '.($results[$email] ? 'valid' : 'invalid')."\n";


if ($results[$email]) {
mail($email, 'Confirm Email', 'Please reply to this email to confirm', 'From:'.$sender."\r\n"); // send email
} else {
echo 'The email addresses you entered is not valid';
}


?>
Böyyük Patron Tarafından 05-11-2008 Tarihinde Gönderilmiştir.   Bu Konuyu Yazdır
Kaynak : 

 

En Son Eklenenler
php
php css ve js dosyalarının cacheden okunmasını engellemek
php
Dosya çalıştırılabilir mi is_executable()
php
Dosya yazılabilir mi is_writable()
php
Dosya okunabilir mi is_readable()
php
Dosya mı, dizin mi is_file() ve is_dir()
php
php Dosya var mı file_exits()
php
PHP include ve require
php
PHP URL Kodları
php
php formlardan gelen verileri almak
php
php web sunucusu değişkenlerini öğrenmek
php
php class (nesne) oluşturmak
php
php dizileri sıralama asort() ve ksort()
php
Diziden kesit alma array_slice()
php
php Dizinin ilk elemanını silme array_shift()
php
php Dizilere değişken ekleme array_push()
php
php Dizileri birleştirme array_merge()
php
php Dizi değişkenleri kullanımı
php
php Dizi Değişken Oluşturmak
php
php Değişkenlerin kapsamı: global ve static
php
php Fonksiyona varsayılan değer vermek
php
php Döngüyü sürdürmek için continue deyimi
php
php Döngüyü sona erdirmek için break deyimi
php
php for döngüsü
php
php do..while döngüsü
php
php while döngüsü
php
php if veya switch kısa şekilde kullanma
php
php switch deyimi
php
php if Deyimi
php
php Tarih ve saat Verisi
php
php Sabit Değerler define
php
php Bir Arttırmak veya Azaltmak için
php
php Aritmetik işlemciler
php
php is_string() is_integer() is_double()
php
php intval(), doubleval(), doubleval()
php
PHP'de Degisken Turleri Kopyalama (Casting)
php
php değişkene atadığımız değerin türünü değiştirmek
php
php Veri Türleri
php
php Değişkenler
php
Include() ve Require() işlevleri
php
do ... while
İletişim : bpatron@codekodu.com
466864Kişi Tarafından Sitemiz Ziyaret Edilmiştir. 11 Kişi Online
Bugün 21 Saat 45 Dakikada Sitemizi Tekil 398 Kişi Ziyaret Etmiştir.
Dün Sitemizi Tekil 401 Kişi Ziyaret Etmiştir.
Sitemizi En Çok Tekil 13-07-2010 Tarihinde 482 Kişi Ziyaret Etmiştir.
Sitemizdeki bilgilerin büyük çoğunluğu alıntıdır.İlgili yazının yazarının veya kaynak sahibinin istemesi halinde ilgili yazı sitemizden kaldırılacaktır.
Sitemizin İmalatı Böyyükpatron Tarafından Yapılmıştır.