0

I have a website that is translated in various languages including French. These pages aren't using Google Translate or any other third party script to do the translations. They have been manually translated.

So on the French's contact us page, I have a php contact form for visitors to fill in. There's french text on the contact us page and I have no problems with character encoding unlike the image below. When the form has been filled in successfully, an automatic message pops up BUT because the french language has special characters, those special characters in the success message have diamond shaped boxes with question marks in it:

enter image description here

MY CODE:

In the header of my contact page I have:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

In my PHP form which generates the success message (obviously javascript is used to display the message), I have (this is just a snippet of my entire php code however I think this part is what matters most):

$msg = wordwrap( $msg, 70 );

$headers = "From: $email\r\nBCC:{$bcc}\r\n" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/html; charset=utf-8" . PHP_EOL;
$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\r\n" . PHP_EOL;

if(mail($address, $e_subject, $msg, $headers)) {


 echo "<div class='success'>";
 echo "<h6>Nous vous remercions de votre demande.</h6>";
 echo "<p><strong>NB:</strong> Si vous n'avez pas reçu une réponse dans 24 heures, veuillez vérifier votre <u style='font-weight:bold'>boîte spam</u>.</p>";
 echo "<div class='close'>&nbsp;</div>";
 echo "</div>";


 } else {

 echo 'ERROR!'; // Dont Edit.

 }

Note in the code above:

$headers .= "Content-type: text/html; charset=utf-8" . PHP_EOL;

I suspect and assume that this is where my problem lies:

charset=utf-8

WHAT I'VE DONE IS:

1) I've tried changing my contact page's http-equiv="Content-Type" to

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

2) and in my php header:

$headers .= "Content-type: text/html; charset=iso-8859-1" . PHP_EOL;

These changes don't work and unfortunately my research on SO isn't getting me closer to a solution (considering everyone's situation is a little different than to perhaps mine). I'm not sure if this header is of any concern?:

$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\r\n" . PHP_EOL;

I appreciate your help and guidance.

user3364730
  • 243
  • 1
  • 5
  • 16
  • 1
    Pick one and stick with it. Charsets should be the same across the entire platform. Personally, I prefer UTF8, but whichever has French characters is fine. Next, you need to set PHP header `header('Content-Type: text/html; charset=utf-8');` - note that headers has to be set before any kind of output (should be called directly after ` – Qirel Mar 10 '16 at 15:06
  • what about the file's encoding, what is it? ANSI? UTF-8 with/without BOM? Could be anything. – Funk Forty Niner Mar 10 '16 at 15:10
  • 1
    Obligatory utf-8 notice: http://stackoverflow.com/questions/279170/utf-8-all-the-way-through/279279#279279 – CD001 Mar 10 '16 at 15:10
  • @Qirel Thanks for your input... I've always stuck to UTF8 and have never mixed any charsets up (neither have I above). I tried adding a PHP header as you suggested and I still get those question marks. At the end of the day, The special characters work 100% fine on my webpage, however as soon as the form is submitted, echoeing the SUCCESS message from the PHP process file (as you can see above), it seems as though the browser cannot encode those special characters IN THE SUCCESS MESSAGE (but the contact page CAN). I'm not sure if you guys require any more code? – user3364730 Mar 10 '16 at 15:57
  • @Qirel - I see in php.ini , I've got `; PHP's default character set is set to empty. ; http://php.net/default-charset ;default_charset = "iso-8859-1"` I'm guessing this should be changed to: `;default_charset = "utf-8"`? – user3364730 Mar 10 '16 at 16:20
  • Using header on every page is the same as the default one. I'm sorry, I'm on mobile at the moment, I'll read through it properly and comment on it when I get home later tonight. – Qirel Mar 10 '16 at 16:23
  • @Qirel - you don't have to be sorry! I understand - I'm appreciate your effort though! Right, I would say don't even worry about this all because I've found a quick fix solution using html entities https://www.utexas.edu/learn/html/spchar.html to replace the character that has that damn question mark! Because I'm very new to this all (it all means gibberish to me) and this is most likely a once-off issue, this solution is convenient and works perfectly (thank god!). If my question doesn't get deleted, then I'll certainly answer this question for people who are in my situation. – user3364730 Mar 10 '16 at 16:58
  • Well, if you're happy with it, I won't indulge it anymore. However, I think it's kind of a dirty solution, and you should rather fix the root issue (charset) than working around it. Speaking from experience, because I did exactly that a good while back - and it caused some headache. Anyhow, I'd recommend to do the following: **1** Set PHP and HTML header on all pages `header('Content-Type: text/html; charset=utf-8');` (before any output as I explained above) and HTML: ``. **2** Check the file-encoding, should be UTF8 w/o BOM – Qirel Mar 10 '16 at 20:57

0 Answers0