<?php if($_POST) { $to_email = "Size Gelecek Olan E Posta Adresini Yazınız Örnek Gidecek Mail Sizinmail@sizinmail.com"; //Recipient email, Replace with own email here $from_email = "Mail Geldiğinde Görünecek E Mail Örnek İnfo@siteniz.com"; //From email address (eg: no-reply@YOUR-DOMAIN.com)
//check if its an ajax request, exit if not if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { $output = json_encode(array( //create JSON data 'type'=>'error', 'text' => 'Maalesef Talep Ajax POST Olmalı' )); die($output); //exit script outputting json data }
//additional php validation if(strlen($user_name)<4){ // If length is less than 4 it will output JSON error. $output = json_encode(array('type'=>'error', 'text' => 'İsim Çok Kısa Veya Boş!')); die($output); } if(strlen($sehir)<4){ // If length is less than 4 it will output JSON error. $output = json_encode(array('type'=>'error', 'text' => 'Sehir Çok Kısa Veya Boş!')); die($output); } if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)){ //email validation $output = json_encode(array('type'=>'error', 'text' => 'Lütfen Geçerli Bir E-Posta Adresi Giriniz!')); die($output); } if(!filter_var($country_code, FILTER_VALIDATE_INT)){ //check for valid numbers in country code field $output = json_encode(array('type'=>'error', 'text' => 'Telefon Ülke Kodunu Lütfen Giriniz! Örnek : +90!')); die($output); } if(!filter_var($phone_number, FILTER_SANITIZE_NUMBER_FLOAT)){ //check for valid numbers in phone number field $output = json_encode(array('type'=>'error', 'text' => 'Telefon Numarasının Tek Basamağını Giriniz')); die($output); } if(strlen($subject)<3){ //check emtpy subject $output = json_encode(array('type'=>'error', 'text' => 'Lütfen Konu Gereklidir Boş Bırakmayınız!')); die($output); } if(strlen($message)<3){ //check emtpy message $output = json_encode(array('type'=>'error', 'text' => 'Çok Kısa Bir Mesaj! Lütfen Dolgun Mesaj Yazınız!')); die($output); }
//email body $message_body = "\nFirma Ismi : ".$user_name."\nSehir : " .$sehir."\nGonderen E-Mail Adresi : ".$user_email."\nGonderenin Telefon Numarasi : (".$country_code.") ". $phone_number."\nIstenilen Talep : " .$message ;
//exit script and output error if we encounter any if($file_error>0) { $mymsg = array( 1=>"Yüklenen Dosya Aşıyor upload_max_filesize Yönergesini php.ini", 2=>"Yüklenen Dosya Aşıyor MAX_FILE_SIZE Belirtildi Direktif HTML Formu", 3=>"Gönderilen Dosya Kısmen Yüklendi", 4=>"Hiç Bir Dosya Yüklenemedi", 6=>"Eksik Geçici Klasör" );
//read from the uploaded file & base64_encode content for the mail $handle = fopen($file_tmp_name, "r"); $content = fread($handle, $file_size); fclose($handle); $encoded_content = chunk_split(base64_encode($content)); ///////////////////////////////////////////////////////////////////////////// $handle1 = fopen($file_tmp_name1, "r"); $content1 = fread($handle1, $file_size1); fclose($handle1); $encoded_content1 = chunk_split(base64_encode($content1)); ///////////////////////////////////////////////////////////////////////////// $handle2 = fopen($file_tmp_name2, "r"); $content2 = fread($handle2, $file_size2); fclose($handle2); $encoded_content2 = chunk_split(base64_encode($content2)); ///////////////////////////////////////////////////////////////////////////// $handle3 = fopen($file_tmp_name3, "r"); $content3 = fread($handle3, $file_size3); fclose($handle3); $encoded_content3 = chunk_split(base64_encode($content3)); ///////////////////////////////////////////////////////////////////////////// $handle4 = fopen($file_tmp_name4, "r"); $content4 = fread($handle4, $file_size4); fclose($handle4); $encoded_content4 = chunk_split(base64_encode($content4)); ///////////////////////////////////////////////////////////////////////////// $handle5 = fopen($file_tmp_name5, "r"); $content5 = fread($handle5, $file_size5); fclose($handle5); $encoded_content5 = chunk_split(base64_encode($content5)); //now we know we have the file for attachment, set $file_attached to true $file_attached = true; $file_attached1 = true; $file_attached2 = true; $file_attached3 = true; $file_attached4 = true; $file_attached5 = true;
}
if($file_attached) //continue if we have the file if($file_attached1) //continue if we have the file if($file_attached2) //continue if we have the file if($file_attached3) //continue if we have the file if($file_attached4) //continue if we have the file if($file_attached5) //continue if we have the file { $boundary = md5("sanwebe.com"); $boundary1 = md5("sanwebe.com"); $boundary2 = md5("sanwebe.com"); $boundary3 = md5("sanwebe.com"); $boundary4 = md5("sanwebe.com"); $boundary5 = md5("sanwebe.com");
var proceed = true; //simple validation at client's end //loop through each field and we simply change border color to red for invalid fields $("#contact_form input[required=true], #contact_form textarea[required=true]").each(function(){ $(this).css('border-color',''); if(!$.trim($(this).val())){ //if this field is empty $(this).css('border-color','red'); //change border color to red proceed = false; //set do not proceed flag } //check invalid email var email_reg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; if($(this).attr("type")=="email" && !email_reg.test($.trim($(this).val()))){ $(this).css('border-color','red'); //change border color to red proceed = false; //set do not proceed flag } });
if(proceed) //everything looks good! proceed... { //data to be sent to server var m_data = new FormData(); m_data.append( 'user_name', $('input[name=name]').val()); m_data.append( 'sehir', $('input[name=sehir]').val()); m_data.append( 'user_email', $('input[name=email]').val()); m_data.append( 'country_code', $('input[name=phone1]').val()); m_data.append( 'phone_number', $('input[name=phone2]').val()); m_data.append( 'subject', $('select[name=subject]').val()); m_data.append( 'msg', $('textarea[name=message]').val()); m_data.append( 'file_attach', $('input[name=file_attach]')[0].files[0]); m_data.append( 'file_attach1', $('input[name=file_attach1]')[0].files[0]); m_data.append( 'file_attach2', $('input[name=file_attach2]')[0].files[0]); m_data.append( 'file_attach3', $('input[name=file_attach3]')[0].files[0]); m_data.append( 'file_attach4', $('input[name=file_attach4]')[0].files[0]); m_data.append( 'file_attach5', $('input[name=file_attach5]')[0].files[0]);
//instead of $.post() we are using $.ajax() //that's because $.ajax() has more options and flexibly. $.ajax({ url: 'contact_me.php', data: m_data, processData: false, contentType: false, type: 'POST', dataType:'json', success: function(response){ //load json data from server and output message if(response.type == 'error'){ //load json data from server and output message output = '<div class="error">'+response.text+'</div>'; }else{ output = '<div class="success">'+response.text+'</div>'; } $("#contact_form #contact_results").hide().html(output).slideDown(); } });
DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.
Üye Ol Şimdi DeğilÜye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.