Allowing special characters in form submit [duplicate]


This question already has an answer here:

<ul><li> <a href="/questions/279170/utf-8-all-the-way-through" dir="ltr" rel="nofollow">UTF-8 all the way through</a> <span class="question-originals-answer-count"> 13 answers </span> </li> </ul>

So I'm coding a contact form for a website, but I want to be able to allow the user to enter non-latin based characters (i.e. é or 車) but I can't exactly figure out where I would set that up - once the user submits the form, it passes it through an AJAX section in jQuery which then processes that to PHP (which prevents the page from refreshing) but trying to use utf8_encode() didn't work and setting the contentType for the data in .ajax() didn't help either, so now I'm not sure what to do.

Anyone able to help me out?

<strong>HTML form</strong>

<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>


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 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); } ?>


Do you have the charset meta?

<meta charset="utf-8">

Also try changing the document's encoding to UTF-8.


  • Greasemonkey script to append text, to a form, when submitted with AJAX?
  • bootstrap 3 disable background after modal popup [duplicate]
  • How to avoid tab stop on the link?
  • Grails redirect with reverse proxy
  • Write “NOT IN” in Doctrine Query Language
  • Polymer paper-input and form submission
  • Encrypting credit card details using AngularJS in Braintree
  • How to best manage SMTP clients
  • Autohotkey script running program with command line arguments
  • Yii2: Using Kartik Depdrop Widget?
  • Dynamically set LESS variables from user settings
  • is it possible to insert a line break in this tooltip?
  • auth.provider is not set to 'password' when user signs-in with email and password
  • How to Add Polymorphic Comments to Feed?
  • testing a POST using phpunit in laravel 4
  • Getting unread count in Sent Folder using Google Apps Script - GMail
  • Xaml, wpf image position and crop issue
  • Getting different value with placeholder over CPU/GPU
  • 550 Access denied - Invalid HELO name
  • Login not working in Firefox in Meteor
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • How do I access an unhandled exception in an MVC Error view?
  • Custom validator control occupying space even though display set to dynamic
  • Email verification using google app script and google forms
  • How do I alternate colors in Flat List (React Native)
  • Listbox within Listbox and scrolling trouble in Windows Phone 7 Silverlight
  • Change multiple background-images with jQuery
  • Email format validation in mvc3 view
  • Insert into database using onclick function
  • Encrypt data by using a public key in c# and decrypt data by using a private key in php
  • Nant, Vault & Windows Integrated Authentication
  • Bug in WPF DataGrid
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • sending/ receiving email in Java
  • Change an a tag attribute in JavaScript based on screen width
  • jquery mobile loadPage not working
  • jQuery tmpl and DataLink beta
  • How can I estimate amount of memory left with calling System.gc()?
  • Unanticipated behavior
  • sending mail using smtp is too slow