İletişim formu Türkçe karakter sorunu.

Arkadaşlar merhaba. Ben kodlar konusunda acemiyim ve kendi çapımda bir şeyler yapmaya çalışıyorum. Ticari falan değil, boz yap deneyip uğraşıyorum. Html kodlarını anlıyorum fakat php konusunda bir bilgim yok. Yaptığım iletişim kutusunu mail adresime yönlendirdim, tüm bilgiler geliyor fakat Türkçe karakterler saçmalıyor. Aşağıda tamami ile kullandığım kodları göndereceğim, eğer bana biri yardımcı olabilirse çok sevinirim.

Öncelikle örnek.com/aaaa.html adresine yerleştirdiğim form kodu:

Alıntı:

<form action='config.php' method='post' id='contact_form'>

<h3>İletişim Formu</h3>

<div class="hr dotted clearfix">&nbsp;</div>

<ul>

<li class="clearfix"> 

<label for="name">İsim</label>

<input type='text' name='name' id='name' />

<div class="clear"></div>

<p id='name_error' class='error'>İsminizi giriniz</p>

</li> 

<li class="clearfix"> 

<label for="email">Email Adresi</label>

<input type='text' name='email' id='email' />

<div class="clear"></div>

<p id='email_error' class='error'>Geçerli bir email adresi giriniz</p>

</li> 

<li class="clearfix"> 

<label for="subject">Konu</label>

<input type='text' name='subject' id='subject' />

<div class="clear"></div>

<p id='subject_error' class='error'>Mesaj konusunu giriniz</p>

</li> 

<li class="clearfix"> 

<label for="message">Mesaj</label>

<textarea name='message' id='message' rows="30" cols="30"></textarea>

<div class="clear"></div>

<p id='message_error' class='error'>Mesajınızı giriniz</p>

</li> 

<li class="clearfix"> 

<p id='mail_success' class='success'>Teşekkür ederiz. En kısa zamanda size geri döneceğiz.</p>

<p id='mail_fail' class='error'>Üzgünüz, bir hata oluştu. Lütfen daha sonra tekrar deneyiniz.</p>

<div id="button">

<input type='submit' id='send_message' class="button" value='Gönder' />

</div>

</li> 

</ul> 

</form>

Sonrasında bir javascript dosyası var (contact.js):

Alıntı:

$(document).ready(function(){

$('#send_message').click(function(e){

//stop the form from being submitted

e.preventDefault();

/* declare the variables, var error is the variable that we use on the end

to determine if there was an error or not */

var error = false;

var name = $('#name').val();

var email = $('#email').val();

var subject = $('#subject').val();

var message = $('#message').val();

/* in the next section we do the checking by using VARIABLE.length

where VARIABLE is the variable we are checking (like name, email),

length is a javascript function to get the number of characters.

And as you can see if the num of characters is 0 we set the error

variable to true and show the name_error div with the fadeIn effect. 

if it's not 0 then we fadeOut the div( that's if the div is shown and

the error is fixed it fadesOut. 

The only difference from these checks is the email checking, we have

email.indexOf('@') which checks if there is @ in the email input field.

This javascript function will return -1 if no occurence have been found.*/

if(name.length == 0){

var error = true;

$('#name_error').fadeIn(500);

}else{

$('#name_error').fadeOut(500);

}

if(email.length == 0 || email.indexOf('@') == '-1'){

var error = true;

$('#email_error').fadeIn(500);

}else{

$('#email_error').fadeOut(500);

}

if(subject.length == 0){

var error = true;

$('#subject_error').fadeIn(500);

}else{

$('#subject_error').fadeOut(500);

}

if(message.length == 0){

var error = true;

$('#message_error').fadeIn(500);

}else{

$('#message_error').fadeOut(500);

}

//now when the validation is done we check if the error variable is false (no errors)

if(error == false){

//disable the submit button to avoid spamming

//and change the button text to Sending...

$('#send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });

/* using the jquery's post(ajax) function and a lifesaver

function serialize() which gets all the data from the form

we submit it to send_email.php */

$.post("send_email.php", $("#contact_form").serialize(),function(result){

//and after the ajax request ends we check the text returned

if(result == 'sent'){

//if the mail is sent remove the submit paragraph

$('#button').remove();

//and show the mail success div with fadeIn

$('#mail_success').fadeIn(500);

}else{

//show the mail failed div

$('#mail_fail').fadeIn(500);

//reenable the submit button by removing attribute disabled and change the text back to Send The Message

$('#send_message').removeAttr('disabled').attr('va lue', 'Submit');

}

});

}

}); 

});

Ardından mail adresini içeren php dosyası(config.php):

Alıntı:

<?php

$email_to = 'örnek@örnek.com'; //the address to which the email will be sent

?>

Son olarak işleyen php dosyası (send_email.php)

Alıntı:

<?php

//we need to get our variables first

include 'config.php';

$name = $_POST['name']; 

$email = $_POST['email'];

$subject = $_POST['subject'];

$message = $_POST['message'];

/*the $header variable is for the additional headers in the mail function,

we are asigning 2 values, first one is FROM and the second one is REPLY-TO.

That way when we want to reply the email gmail(or yahoo or hotmail...) will know 

who are we replying to. */

$headers = "From: $email\r\n";

$headers .= "Reply-To: $email\r\n";

if(mail($email_to, $subject, $message, $headers)){

echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent.. 

}else{

echo 'failed';// ... or this one to tell it that it wasn't sent 

}

?>

Tüm herşey burada, bu sistemde mailime gelen Türkçe karakter sorunundan nasıl kurtulurum biliyor musunuz? 

Herkese kolay gelsin.

Orkun.

2011-11-15 01:03:04 Edit:2011-11-15 01:04:35

alicilinAli Fırat Güler
Yazan:1234qwer

Arkadaşlar merhaba. Ben kodlar konusunda acemiyim ve kendi çapımda bir şeyler yapmaya çalışıyorum. Ticari falan değil, boz yap deneyip uğraşıyorum. Html kodlarını anlıyorum fakat php konusunda bir bilgim yok. Yaptığım iletişim kutusunu mail adresime yönlendirdim, tüm bilgiler geliyor fakat Türkçe karakterler saçmalıyor. Aşağıda tamami ile kullandığım kodları göndereceğim, eğer bana biri yardımcı olabilirse çok sevinirim.

Öncelikle örnek.com/aaaa.html adresine yerleştirdiğim form kodu:

Alıntı:

<form action='config.php' method='post' id='contact_form'>

<h3>İletişim Formu</h3>

<div class="hr dotted clearfix">&nbsp;</div>

<ul>

<li class="clearfix"> 

<label for="name">İsim</label>

<input type='text' name='name' id='name' />

<div class="clear"></div>

<p id='name_error' class='error'>İsminizi giriniz</p>

</li> 

<li class="clearfix"> 

<label for="email">Email Adresi</label>

<input type='text' name='email' id='email' />

<div class="clear"></div>

<p id='email_error' class='error'>Geçerli bir email adresi giriniz</p>

</li> 

<li class="clearfix"> 

<label for="subject">Konu</label>

<input type='text' name='subject' id='subject' />

<div class="clear"></div>

<p id='subject_error' class='error'>Mesaj konusunu giriniz</p>

</li> 

<li class="clearfix"> 

<label for="message">Mesaj</label>

<textarea name='message' id='message' rows="30" cols="30"></textarea>

<div class="clear"></div>

<p id='message_error' class='error'>Mesajınızı giriniz</p>

</li> 

<li class="clearfix"> 

<p id='mail_success' class='success'>Teşekkür ederiz. En kısa zamanda size geri döneceğiz.</p>

<p id='mail_fail' class='error'>Üzgünüz, bir hata oluştu. Lütfen daha sonra tekrar deneyiniz.</p>

<div id="button">

<input type='submit' id='send_message' class="button" value='Gönder' />

</div>

</li> 

</ul> 

</form>

Sonrasında bir javascript dosyası var (contact.js):

Alıntı:

$(document).ready(function(){

$('#send_message').click(function(e){

//stop the form from being submitted

e.preventDefault();

/* declare the variables, var error is the variable that we use on the end

to determine if there was an error or not */

var error = false;

var name = $('#name').val();

var email = $('#email').val();

var subject = $('#subject').val();

var message = $('#message').val();

/* in the next section we do the checking by using VARIABLE.length

where VARIABLE is the variable we are checking (like name, email),

length is a javascript function to get the number of characters.

And as you can see if the num of characters is 0 we set the error

variable to true and show the name_error div with the fadeIn effect. 

if it's not 0 then we fadeOut the div( that's if the div is shown and

the error is fixed it fadesOut. 

The only difference from these checks is the email checking, we have

email.indexOf('@') which checks if there is @ in the email input field.

This javascript function will return -1 if no occurence have been found.*/

if(name.length == 0){

var error = true;

$('#name_error').fadeIn(500);

}else{

$('#name_error').fadeOut(500);

}

if(email.length == 0 || email.indexOf('@') == '-1'){

var error = true;

$('#email_error').fadeIn(500);

}else{

$('#email_error').fadeOut(500);

}

if(subject.length == 0){

var error = true;

$('#subject_error').fadeIn(500);

}else{

$('#subject_error').fadeOut(500);

}

if(message.length == 0){

var error = true;

$('#message_error').fadeIn(500);

}else{

$('#message_error').fadeOut(500);

}

//now when the validation is done we check if the error variable is false (no errors)

if(error == false){

//disable the submit button to avoid spamming

//and change the button text to Sending...

$('#send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });

/* using the jquery's post(ajax) function and a lifesaver

function serialize() which gets all the data from the form

we submit it to send_email.php */

$.post("send_email.php", $("#contact_form").serialize(),function(result){

//and after the ajax request ends we check the text returned

if(result == 'sent'){

//if the mail is sent remove the submit paragraph

$('#button').remove();

//and show the mail success div with fadeIn

$('#mail_success').fadeIn(500);

}else{

//show the mail failed div

$('#mail_fail').fadeIn(500);

//reenable the submit button by removing attribute disabled and change the text back to Send The Message

$('#send_message').removeAttr('disabled').attr('va lue', 'Submit');

}

});

}

}); 

});

Ardından mail adresini içeren php dosyası(config.php):

Alıntı:

<?php

$email_to = 'örnek@örnek.com'; //the address to which the email will be sent

?>

Son olarak işleyen php dosyası (send_email.php)

Alıntı:

<?php

//we need to get our variables first

include 'config.php';

$name = $_POST['name']; 

$email = $_POST['email'];

$subject = $_POST['subject'];

$message = $_POST['message'];

/*the $header variable is for the additional headers in the mail function,

we are asigning 2 values, first one is FROM and the second one is REPLY-TO.

That way when we want to reply the email gmail(or yahoo or hotmail...) will know 

who are we replying to. */

$headers = "From: $email\r\n";

$headers .= "Reply-To: $email\r\n";

if(mail($email_to, $subject, $message, $headers)){

echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent.. 

}else{

echo 'failed';// ... or this one to tell it that it wasn't sent 

}

?>

Tüm herşey burada, bu sistemde mailime gelen Türkçe karakter sorunundan nasıl kurtulurum biliyor musunuz? 

Herkese kolay gelsin.

Orkun.

post ile aldığın bilgileri karakter setini değiştir. iconv fonksiyonunu bir araştır. onunla işini kolayca halledebilirsin.

2011-11-15 11:24:21

phpkodlari.com © 2009 Herkes Php öğrenecek
Eglence ve Oyun: Gamikro