|
|
|
|
|
|
|
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 : |
|
|
PHP |
girilen tarihi kontrol etmek | | function check_date($date){
$seperator = "[\/\-\.]";
return preg_match("#^(((0?[1-9]|1\d|2[0-8]){$seperator}(0?[1-9]|1[012])|(29|30){$seperator}(0?[13456789]|1[012])|31{$seperator}(0?[13578]|1[02])){$seperator}(19|[2-9]\d)\d{2}|29{$seperator}0?2{$seperator}((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$#", $date)==1?true:false;
}
check_date("30.9.2005"); //valid
check_date("32.9.2005"); //invalid
check_date("29.1.2005"); //valid
check_date("29.2.2005"); //invalid |
Böyyük Patron Tarafından 04-11-2008 Tarihinde Gönderilmiştir.
Bu Konuyu Yazdır
Kaynak : |
|
|
Diğer Konular |
FTP Status Codes statü kodları | | 110 Restart marker reply.
In this case, the text is exact and not left to the particular implementation; it must read: MARK yyyy = mmmm, where yyyy is User-process data stream marker, and mmmm server's equivalent marker (note the spaces between markers and sign).
120 Service ready in nnn minutes.
125 Data connection already open; transfer starting.
150 File status okay; about to open data connection.
200 Command okay.
202 Command not implemented, superfluous at this site.
211 System status, or system help reply.
212 Directory status.
213 File status.
214 Help message.
On how to use the server or the meaning of a particular non-standard command. This reply is useful only to the human user.
215 NAME system type.
Where NAME is an official system name from the list in the Assigned Numbers document.
220 Service ready for new user.
221 Service closing control connection.
Logged out if appropriate.
225 Data connection open; no transfer in progress.
226 Closing data connection.
Requested file action successful (for example, file transfer or file abort).
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
230 User logged in, proceed.
250 Requested file action okay, completed.
257 "PATHNAME" created.
331 User name okay, need password.
332 Need account for login.
350 Requested file action pending further information.
421 Service not available, closing control connection.
This may be a reply to any command if the service knows it must shut down.
425 Can't open data connection.
426 Connection closed; transfer aborted.
450 Requested file action not taken.
File unavailable (e.g., file busy).
451 Requested action aborted: local error in processing.
452 Requested action not taken.
Insufficient storage space in system.
500 Syntax error, command unrecognized.
This may include errors such as command line too long.
501 Syntax error in parameters or arguments.
502 Command not implemented.
503 Bad sequence of commands.
504 Command not implemented for that parameter.
530 Not logged in.
532 Need account for storing files.
550 Requested action not taken.
File unavailable (e.g., file not found, no access).
551 Requested action aborted: page type unknown.
552 Requested file action aborted.
Exceeded storage allocation (for current directory or dataset).
553 Requested action not taken.
File name not allowed. |
Böyyük Patron Tarafından 04-11-2008 Tarihinde Gönderilmiştir.
Bu Konuyu Yazdır
Kaynak : |
|
|
Diğer Konular |
HTTP / 1.1 Status Codes statü kodları | | 100 Continue
101 Switching Protocols
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Parial Content
300 Multiple Choises
301 Moved Permanently
302 Found
303 See Other
304 Not Modified
305 Use Proxy
306 (Unused)
307 Temporary Redirect
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Long
415 Unsupported Media Type
416 Requested Range Not Satisfiable
417 Expectation Failed
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported |
Böyyük Patron Tarafından 04-11-2008 Tarihinde Gönderilmiştir.
Bu Konuyu Yazdır
Kaynak : |
|
|
Diğer Konular |
Simple Mail Transfer Protocol (SMTP) code kodları | | 200 Success (see RFC 876)
211 System status, or system help reply
214 Help message
220 Service ready
221 Service closing transmission channel
250 Requested mail action okay, completed
251 User not local
354 Start mail input; end with <CRLF>.<CRLF>
421 Service not available, closing transmission channel
450 Requested mail action not taken: mailbox unavailable
451 Requested action aborted: local error in processing
452 Requested action not taken: insufficient system storage
500 Syntax error, command unrecognised
501 Syntax error in parameters or arguments
502 Command not implemented
503 Bad sequence of commands
504 Command parameter not implemented
521 Domain does not accept mail (see RFC 1846)
530 Access denied
550 Requested action not taken: mailbox unavailable
551 User not local
552 Requested mail action aborted: exceeded storage allocation
553 Requested action not taken: mailbox name not allowed
554 Transaction failed |
Böyyük Patron Tarafından 04-11-2008 Tarihinde Gönderilmiştir.
Bu Konuyu Yazdır
Kaynak : |
|
|
|