所以我正在编写一个网站的联系表格,但我希望能够允许用户输入非基于拉丁语的字符(即é或车)但我无法弄清楚我要设置的位置一旦用户提交表单,它会通过jQuery中的AJAX部分传递它,然后将其处理为PHP(这会阻止页面刷新)但尝试使用utf8_encode()不起作用并为其设置contentType .ajax()中的数据也没有帮助,所以现在我不知道该怎么做。
任何人都可以帮助我吗?
HTML表单
<form action="" id="contactUs" method="post">
<div class="input-group">
<span class="input-group-addon">name</span>
<input type="text" class="form-control" placeholder="Your Name/Company" tabindex="1" name= "name" id="name" />
</div>
<div class="input-group">
<span class="input-group-addon" style="padding-right: 18px;">mail</span>
<input type="email" class="form-control" placeholder="Your/Your Company Email" tabindex="2" name="email" id="email" />
</div>
<div class="input-group">
<span class="input-group-addon" style="padding-right: 18px;">subject</span>
<input type="text" class="form-control" placeholder="The subject of your message" tabindex="2" name="subject" id="subject" />
</div>
<div class="input-group">
<span class="input-group-addon" style="padding-right: 18px;">message</span>
<textarea class="form-control" placeholder="What's on your mind?" cols="100" rows="4" tabindex="3" name="msg" id="msg"></textarea>
</div>
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" type="submit" style="-webkit-border-radius: 8px; border-radius: 8px; position: relative; left: 41%;" id="submit">Submit</button>
</span>
</div>
</form>
的jQuery
var dataString = 'name=' + name + '&email=' + email + "&subject=" + subject + '&msg=' + msg;
$.ajax ({
type: "POST",
url: "process.php",
data: {
name : name,
email : email,
subject :subject,
msg : msg
},
contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15",
dataType: 'json',
complete: function() {
$("#error").hide();
$("#errormail").hide();
$("textarea#msg").css("background-color", "#ffffff");
$("input#email").css("background-color", "#ffffff");
$("input#name").css("background-color", "#ffffff");
$("#success").show();
setTimeout(
function(){ $('#success').fadeOut() }, 5000
);
$( '#contactUs' ).each(function(){
this.reset();
});
}
});
PHP
<?php
if(isset($_POST['email'])) {
$email_to = "info@infinitedream.net ";
$email_from = $_POST['email']; // required
$email_subject = $_POST['subject'];
$name = $_POST['name']; // required
$message = $_POST['msg']; // required
$email_message = '<html><body>';
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= '<table rules="all" style="border: 1px solid #666;" cellpadding="10">';
$email_message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($name) . "</td></tr>";
$email_message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($email_from) . "</td></tr>";
$email_message .= "<tr><td><strong>Message:</strong> </td><td>" . utf8_encode($message) . "</td></tr>";
$email_message .= "</table>";
$email_message .= "</body></html>";
// create email headers
$headers = 'From: '.$email_from."\r\n";
$headers = 'Reply-To: '.$email_from."\r\n";
$headers = 'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers = "Content-type:text/html;charset=iso-8859-1" . "\r\n";
mail($email_to, $email_subject, $email_message, $headers);
}
?>
答案 0 :(得分:0)
你有charset meta吗?
<meta charset="utf-8">
还尝试将文档的编码更改为UTF-8。