Email Adresi Doğrulama

<?php
class emailKontrol{
	var $email;
	function emailKontrol($email){
		$this->email = $email;
	}
	function dogrula(){
		$dogru = true;
		if (filter_var($this->email, FILTER_VALIDATE_EMAIL)) {
			if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,8})$/", $this->email)){
				$dogru = false;
			}
			$dogru=true;
		}else{
			$dogru=false;
		}
		if($dogru == false){
			return "$this->email <i>düzgün <u>biçimlendirilmemiş<u></i>.";
		}else{
			return "$this->email <b>doğrulandı</b>.";
		}
	}
}
$email= new emailKontrol("ulusanyazilim@gmail.com");
echo $email->dogrula();
$email= new emailKontrol("ulusanyazilim@gmail.com@com");
echo $email->dogrula();
?>

Çıktısı

ulusanyazilim@gmail.com <b>doğrulandı</b>.
ulusanyazilim@gmail.com@com <i>düzgün <u>biçimlendirilmemiş<u></i>.

 

Gmail SMTP E-Mail Gönderme

$user = 'xxxx@gmail.com';
$pass = '1234';
kısmını değiştirerek kullanabilirsiniz...

 <?php header('Content-Type: text/html; charset=utf-8');
$smtp = fsockopen("smtp.gmail.com", 587, $errno, $errstr, 15);

function get($smtp){
 $send = '';
 $sr = fgets($smtp,1024);
 while( $sr ){
 $send .= $sr;
 if( $sr[3] != '-' ){ break; }
 $sr = fgets($smtp,1024);
 }
 return $send;
}
function put($cmd,$smtp){
 fputs($smtp,$cmd."\r\n",1024);
}

function smtp_mail($to, $subject, $message, $headers = '',$smtp)
{
 $recipients = explode(',', $to);
 $user = 'xxxx@gmail.com';
 $pass = '1234';
 echo '<pre>';
 get($smtp);
 
 put("EHLO ".$_SERVER['HTTP_HOST'],$smtp);
 echo get($smtp); // 250
 put("STARTTLS",$smtp);
 echo get($smtp); // 220
 
 if(false == stream_socket_enable_crypto($smtp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)){
 die("unable to start tls encryption");
 }
 put('AUTH LOGIN',$smtp);
 echo get($smtp); // 334
 put(base64_encode($user),$smtp);
 echo get($smtp); // 334
 put(base64_encode($pass),$smtp);
 echo get($smtp); // 235
 put('MAIL FROM: <'.$user.'>',$smtp);
 echo get($smtp); // 250
 foreach ($recipients as $email)
 {
 put('RCPT TO: <'.$email.'>',$smtp);
 echo get($smtp); // 250
 }
 put('DATA',$smtp);
 echo get($smtp); // 354
 fwrite($smtp, 'Subject: '.$subject."\r\n".'To: <'.implode('>, <', $recipients).'>'."\r\n".$headers."\r\n\r\n".$message."\r\n");
 fwrite($smtp, '.'."\r\n");
 echo get($smtp); // 250
 put("EHLO ".$_SERVER['HTTP_HOST'],$smtp);
 echo get($smtp); // 250
 put("QUIT",$smtp);
 echo get($smtp);
 echo "</pre>"; 
 fclose($smtp); 
 return true;
} 
function send_test_email($smtp) { 
 if(smtp_mail('ulusanyazilim@gmail.com', 'Konu', 'Mesaj','',$smtp)) {
  echo "Gönderim Başarılı.";
 }else{
  echo "Bir Hata Oluştu.";
 } 
} 
send_test_email($smtp); 
?>