Merhaba arkadaşlar, düzenlemek istedigim temada İletişim bölümü var ben SMTP ile mail göndermeyi entegre etmek istiyorum.
Temada kodlanan bölüm;
<section id="contact" class="section green">
<div class="container">
<h4>İlerişime Geçin</h4>
<p>
</p>
<div class="blankdivider30">
</div>
<div class="row">
<div class="span12">
<div class="cform" id="contact-form">
<div id="sendmessage">Your message has been sent. Thank you!</div>
<div id="errormessage"></div>
<form action="mail_ayar.php" method="post" role="form" class="contactForm">
<div class="row">
<div class="span6">
<div class="field your-name form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="field your-email form-group">
<input type="text" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="field subject form-group">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
<div class="validation"></div>
</div>
</div>
<div class="span6">
<div class="field message form-group">
<textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validation"></div>
</div>
<input type="submit" value="Send message" class="btn btn-theme pull-left">
</div>
</div>
</form>
</div>
</div>
<!-- ./span12 -->
</div>
</div>
</section>SMTP Mail Göndermek için yoncunun verdiği kodlar;
------------------------------------------------------------------------
<?php
class PHPMailer{
public $Version = '5.2.16';
public $Priority = null;
public $CharSet = 'UTF-8';
public $ContentType = 'text/plain';
public $Encoding = '8bit';
public $ErrorInfo = '';
public $From = 'info@xxx.com';
public $FromName = 'Mail Form';
public $Sender = '';
public $ReturnPath = '';
public $Subject = '';
public $Body = '';
public $AltBody = '';
public $Ical = '';
protected $MIMEBody = '';
protected $MIMEHeader = '';
protected $mailHeader = '';
public $WordWrap = 0;
public $Mailer = 'smtp';
public $Sendmail = '/usr/sbin/sendmail';
public $UseSendmailOptions = true;
public $PluginDir = '';
public $ConfirmReadingTo = '';
public $Hostname = '';
public $MessageID = '';
public $MessageDate = '';
public $Host = 'mail.yoncu.com';
public $Port = 587;
public $Helo = '';
public $SMTPSecure = 'tls';
public $SMTPAutoTLS = true;
public $SMTPAuth = false;
public $SMTPOptions = array('ssl'=>array('verify_peer'=>false,'verify_peer_name'=>false,'allow_self_signed'=>true,));
public $Username = '';
public $Password = '';
public $AuthType = '';
public $Realm = '';
public $Workstation = '';
public $Timeout = 300;
public $SMTPDebug = 0;
public $Debugoutput = 'echo';
public $SMTPKeepAlive = false;
public $SingleTo = false;
public $SingleToArray = array();
public $do_verp = false;
public $AllowEmpty = false;
public $LE = "\n";
public $DKIM_selector = '';
public $DKIM_identity = '';
public $DKIM_passphrase = '';
public $DKIM_domain = '';
public $DKIM_private = '';
public $DKIM_private_string = '';
public $action_function = '';
public $XMailer = '';
public static $validator = 'auto';
protected $smtp = null;
protected $to = array();
protected $cc = array();
protected $bcc = array();
protected $ReplyTo = array();
protected $all_recipients = array();
protected $RecipientsQueue = array();
protected $ReplyToQueue = array();
protected $attachment = array();
protected $CustomHeader = array();
protected $lastMessageID = '';
protected $message_type = '';
protected $boundary = array();
protected $language = array();
protected $error_count = 0;
protected $sign_cert_file = '';
protected $sign_key_file = '';
protected $sign_extracerts_file = '';
protected $sign_key_pass = '';
protected $exceptions = false;
protected $uniqueid = '';
const STOP_MESSAGE = 0;
const STOP_CONTINUE = 1;
const STOP_CRITICAL = 2;
const CRLF = "\r\n";
const MAX_LINE_LENGTH = 998;
public function __construct($exceptions = null)
{
if ($exceptions !== null) {
$this->exceptions = (boolean)$exceptions;
}
}
public function __destruct(){
$this->smtpClose();
}
private function mailPassthru($to, $subject, $body, $header, $params){
if (ini_get('mbstring.func_overload') & 1) {
$subject = $this->secureHeader($subject);
} else {
$subject = $this->encodeHeader($this->secureHeader($subject));
}
if (ini_get('safe_mode') or !$this->UseSendmailOptions or is_null($params)){
$result = @mail($to, $subject, $body, $header);
} else {
$result = @mail($to, $subject, $body, $header, $params);
}
return $result;
}
protected function edebug($str){
if ($this->SMTPDebug <= 0) {
return;
}
nd $line == '') {
$in_headers = false;
}
while (isset($line[self::MAX_LINE_LENGTH])) {
$pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
if (!$pos) {
$pos = self::MAX_LINE_LENGTH - 1;
$lines_out[] = substr($line, 0, $pos);
$line = substr($line, $pos);
} else {
$lines_out[] = substr($line, 0, $pos);
$line = substr($line, $pos + 1);
}
if ($in_headers) {
$line = "\t" . $line;
}
}
$lines_out[] = $line;
foreach ($lines_out as $line_out) {
if (!empty($line_out) and $line_out[0] == '.') {
$line_out = '.' . $line_out;
}
$this->client_send($line_out . self::CRLF);
}
}
$savetimelimit = $this->Timelimit;
$this->Timelimit = $this->Timelimit * 2;
$result = $this->sendCommand('DATA END', '.', 250);
$this->Timelimit = $savetimelimit;
return $result;
}
public function hello($host = '')
{
return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
}
protected function sendHello($hello, $host)
{
$noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
$this->helo_rply = $this->last_reply;
if ($noerror) {
$this->parseHelloFields($hello);
} else {
$this->server_caps = null;
}
return $noerror;
}
protected function parseHelloFields($type)
{
$this->server_caps = array();
$lines = explode("\n", $this->helo_rply);
foreach ($lines as $n => $s) {
$s = trim(substr($s, 4));
if (empty($s)) {
continue;
}
$fields = explode(' ', $s);
if (!empty($fields)) {
if (!$n) {
$name = $type;
$fields = $fields[0];
} else {
$name = array_shift($fields);
switch ($name) {
case 'SIZE':
$fields = ($fields ? $fields[0] : 0);
break;
case 'AUTH':
if (!is_array($fields)) {
$fields = array();
}
break;
default:
$fields = true;
}
}
$this->server_caps[$name] = $fields;
}
}
}
public function mail($from)
{
$useVerp = ($this->do_verp ? ' XVERP' : '');
return $this->sendCommand(
'MAIL FROM',
'MAIL FROM:<' . $from . '>' . $useVerp,
250
);
}
public function quit($close_on_error = true)
{
$noerror = $this->sendCommand('QUIT', 'QUIT', 221);
$err = $this->error;
if ($noerror or $close_on_error) {
$this->close();
$this->error = $err;
}
return $noerror;
}
public function recipient($address)
{
return $this->sendCommand(
'RCPT TO',
'RCPT TO:<' . $address . '>',
array(250, 251)
);
}
public function reset()
{
return $this->sendCommand('RSET', 'RSET', 250);
}
protected function sendCommand($command, $commandstring, $expect)
{
if (!$this->connected()) {
$this->setError("Called $command without being connected");
return false;
}
if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) {
$this->setError("Uygulanan komut listesi ".$command);
return false;
}
$this->client_send($commandstring . self::CRLF);
$this->last_reply = $this->get_lines();
$matches = array();
if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
$code = $matches[1];
$code_ex = (count($matches) > 2 ? $matches[2] : null);
$detail = preg_replace(
"/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m",
'',
$this->last_reply
);
} else {
$code = substr($this->last_reply, 0, 3);
$code_ex = null;
$detail = substr($this->last_reply, 4);
}
$this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
if (!in_array($code, (array)$expect)) {
$this->setError(
"$command Komut başarısız",
$detail,
$code,
$code_ex
);
$this->edebug(
'SMTP HATA: ' . $this->error['error'] . ': ' . $this->last_reply,
self::DEBUG_CLIENT
);
return false;
}
$this->setError('');
return true;
}
public function sendAndMail($from)
{
return $this->sendCommand('SAML', "SAML FROM:$from", 250);
}
public function verify($name){
return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
}
public function noop(){
return $this->sendCommand('NOOP', 'NOOP', 250);
}
public function turn(){
$this->setError('SMTP TURN Komutu uygulanamadı');
$this->edebug('SMTP Uyari: ' . $this->error['error'], self::DEBUG_CLIENT);
return false;
}
public function client_send($data){
$this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
return fwrite($this->smtp_conn, $data);
}
public function getError(){
return $this->error;
}
public function getServerExtList(){
return $this->server_caps;
}
public function getServerExt($name){
if (!$this->server_caps){
$this->setError('Mail gönderilemedi');
return null;
}
if (!array_key_exists($name, $this->server_caps)) {
if ($name == 'HELO') {
return $this->server_caps['EHLO'];
}
if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) {
return false;
}
$this->setError('HELO handshake was used. Client knows nothing about server extensions');
return null;
}
return $this->server_caps[$name];
}
public function getLastReply(){
return $this->last_reply;
}
protected function get_lines(){
if (!is_resource($this->smtp_conn)) {
return '';
}
$data = '';
$endtime = 0;
stream_set_timeout($this->smtp_conn, $this->Timeout);
if ($this->Timelimit > 0) {
$endtime = time() + $this->Timelimit;
}
while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
$str = @fgets($this->smtp_conn, 515);
$this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
$this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL);
$data .= $str;
if ((isset($str[3]) and $str[3] == ' ')) {
break;
}
$info = stream_get_meta_data($this->smtp_conn);
if ($info['timed_out']) {
$this->edebug(
'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)',
self::DEBUG_LOWLEVEL
);
break;
}
if ($endtime and time() > $endtime) {
$this->edebug(
'SMTP -> get_lines(): timelimit reached ('.
$this->Timelimit . ' sec)',
self::DEBUG_LOWLEVEL
);
break;
}
}
return $data;
}
public function setVerp($enabled = false){
$this->do_verp = $enabled;
}
public function getVerp(){
return $this->do_verp;
}
protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = ''){
$this->error = array(
'error' => $message,
'detail' => $detail,
'smtp_code' => $smtp_code,
'smtp_code_ex' => $smtp_code_ex
);
}
public function setDebugOutput($method = 'echo'){
$this->Debugoutput = $method;
}
public function getDebugOutput(){
return $this->Debugoutput;
}
public function setDebugLevel($level = 0){
$this->do_debug = $level;
}
public function getDebugLevel(){
return $this->do_debug;
}
public function setTimeout($timeout = 0){
$this->Timeout = $timeout;
}
public function getTimeout(){
return $this->Timeout;
}
protected function errorHandler($errno, $errmsg){
$notice = 'Bağlantı: Sunucuya bağlanılamadı.';
$this->setError(
$notice,
$errno,
$errmsg
);
$this->edebug(
$notice . ' Hata numarası ' . $errno . '. "Hata bildirimi: ' . $errmsg,
self::DEBUG_CONNECTION
);
}
}
class phpmailerException extends Exception {
public function errorMessage(){
$errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
return $errorMsg;
}
}
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = ((isset($MailHost) and $MailHost != "")?$MailHost:'127.0.0.1');
$mail->Port = ((isset($MailPort) and $MailPort != "")?$MailPort:587);
$mail->SMTPSecure = ((isset($MailGuvenlik))?$MailGuvenlik:'tls');
$mail->Username = $SiteMaili;
$mail->Password = $MailSifre;
$mail->SetFrom($SiteMaili, $SiteMaili);
$mail->Subject = $MailKonu;
$body = $MesajMetni;
$mail->MsgHTML($body);
$mail->AddAddress($MailiGonder, $MailKonu);
if(!$mail->Send()){
$MailHata = $mail->ErrorInfo;
}------------------------------------------------------------------------
İletisim.php
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
/**
* D İ K K A T
* Bunu Okuyunuz:
* Bu forma kendi sitenize göre düzenleyebilir entegre edebilirsiniz.
* Aşağıda yer alan 4 bilgiyi doldurmalısınız.
* Mail sunucu adresinizi smtp.mailadresim.com veya mail.mailadresim.com gibi $MailHost alanına yazmalısınız.
* Hostunuzun yönetimindeki mail yönetimine girerek mail oluşturmalı ve $SiteMaili karşısındaki tırnaklar arasına bu maili yazmalısınız.
* Mail oluştururken yazdığınız mail şifresini $MailSifre karşısındaki tırnaklar içerisine yazmalısınız.
* $MailGuvenlik değerini "tls" kullanabilirsiniz, null yaparsanız her sunuvu desteklemeyebilir, "ssl" yapmanız durumunda ise portu 465 yapmalısınız.
* Son olarak $MailiGonder karşısında da müşteri formu doldurunda mailin hangi mail adresinize gelmesini istiyorsanız onu yazmalısınız. $SiteMaili ile aynı olabilir.
* Destek: Yaşadığınız problemler ile ilgili veya formun tarafımızdan sitenize entegre edilmesini isterseniz www.yoncu.com özel destek alabilirsiniz.
*/
$MailHost = 'smtp.yoncu.com';
$SiteMaili = 'info@xxx.com';
$MailSifre = "9418RBvj:";
$MailiGonder = 'info@xxx.com';
$MailKonu = 'Siteden Mesaj Var';
$MesajMetni = 'Gönderilen Bilgiler:';
$MailPort = 587;
$MailGuvenlik = 'tls';
foreach($_POST as $input=>$value){$MesajMetni.='<br/><b>'.$input.': </b>'.$value;}
include("mail_ayar.php");
}
?>SMTP mail protokolünü entegre etmem için tam olarak ne yapmam lazım kafam çok karışık


Not: SMTP Mail Göndermek için yoncunun verdiği kodların bir kısmını ekleyebildim 40.000 karakter sınırı var lazımsa bir yere upload edebilirim.