所以我正在为一个网站编写一个联系表格,但我希望能够允许用户输入非拉丁字符(即 é 或 车),但我无法确切知道我将在哪里设置它 -一旦用户提交表单,它会通过 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);
}
?>