Formlarda SMTP Doğrulama

Sunucularımızda spam mailleri önleme ve hesaplarınızdan habersiz illegal mail gönderimini engellemek için formmail() fonkisyonları kapatılmıştır. Web siteniz üzerinden mail gönderimi yapmak için de SMTP doğrulaması yapmanız gerekmektedir. Buna örnek olarak aşağıdaki kodları kullanabilirsiniz..


smtpconfig.php dosyasını oluşturup aşağıdaki kodları yazınız. username/password sizin mail adresiniz ve parolasıdır. 

<?php
//Mail bilgileri

$SmtpServer="domain.com";
$SmtpPort="587"; //default
$SmtpUser="username";    
$SmtpPass="password";

?>

 

Daha sonra class dosyasını oluşturuyoruz. 

smtpclass.php

<?php

class SMTPClient
{

function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
{

$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;

if ($SmtpPort == "") 
{
$this->PortSMTP = 25;
}

else

{
$this->PortSMTP = $SmtpPort;
}
}

function SendMail ()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP)) 
{
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n"); 
$talk["hello"] = fgets ( $SMTPIN, 1024 ); 
fputs($SMTPIN, "auth login\r\n");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."\r\n");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."\r\n");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n"); 
$talk["From"] = fgets ( $SMTPIN, 1024 ); 
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n"); 
$talk["To"] = fgets ($SMTPIN, 1024); 
fputs($SMTPIN, "DATA\r\n");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ... 
fputs ($SMTPIN, "QUIT\r\n"); 
fclose($SMTPIN); 

// 


return $talk;

}

?>



Ve son olarak da formumuzu oluşturuyoruz. 

index.php

<?php

include('smtpconfig.php');
include('smtpclass.php');
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['sub'];
$body = $_POST['message'];
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}

?>
<form method="post" action="">

To:<input type="text" name="to" />
From :<input type='text' name="from" />
Subject :<input type='text' name="sub" />
Message :<textarea name="message"></textarea>
<input type="submit" value=" Send " />

</form>



Bu şekilde form mail gönderimi yapabilirsiniz. 

 

  • 181 Uživatelům pomohlo
Byla tato odpověď nápomocná?

Související články

Outlook 2007 POP3 E-mail Kurulumu

Microsoft Outlook 2007 programının üst kısmında bulunan Araçlar menüsünden Hesap Ayarları...

Android Cihazlarda E-Mail kurulumu

Günümüz akıllı telefonlarında çoğunlukla kullanılan Android işletim sistemi için E-mail ayarları...

Web Mail Giriş

E-Postalarınıza internet'den ulaşmak için tarayıcınıza http://www.alanadiniz.com/webmail yazmanız...

Outlook 2010 POP3 E-mail Kurulumu

Size verilen E-mail adresiniz ve şifrenizle Microsoft Outlook 2010 (Office 2010) ayarlarınızı şu...

İOS Cihazlara E-Mail Kurulumu

İOS Cihazlarımızda E-posta ayarlarını yapmak için önçelikle telefonunuzun ana menüsünden Ayarlar...

Powered by WHMCompleteSolution