2

I have a form that emails to my email address. Everything works fine, except when someone pastes something from MS Word into the form. All the text comes through, but the encoding on the apostrophes and double quotes are all messed up. They come through as strange characters.

Is there anyway to easily fix this issue?

kylex
  • 14,178
  • 33
  • 114
  • 175
  • Not enough information. What is the encoding of the e-mail? What is the encoding in which the form data is submitted? What gets through (which octets)? – Artefacto Jan 20 '11 at 19:35
  • @Artefacto: UTF-8 is the encoding it is being sent as through the form as well as the encoding of the email being sent. I'm not sure what you mean by what octets get through. – kylex Jan 20 '11 at 20:37

4 Answers4

9

For me this solution works fine:

Convert windows converted string to utf-8.

$str = iconv("cp1252","UTF-8", $str);
  • cp866 MS DOS Cyrillic
  • cp1251 Windows Cyrillic
  • cp1253 Windows west european language

Futher information about iconv()

Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134
Max
  • 131
  • 1
  • 4
2

MS Word uses apostrophes and quotes that are not valid under UTF8. Here's an article on SO about it:

PHP - Getting rid of curly apostrophes

Community
  • 1
  • 1
fiiv
  • 1,267
  • 1
  • 8
  • 16
0

Have you tried using strip_tags() ?

Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134
Cory Dee
  • 2,858
  • 6
  • 40
  • 55
0

You need to have same charset on both the form html page, and the page which generates the email content. For example, set utf-8 on the html page which displays the form. Also, when creating the mail message on submit, set the charset in header to be utf-8. That works fine. If you are using phpmailer for email, then you can set the charset through the phpmailer class object like $mail->Charset = 'utf-8' This works well when you are storing and retrieving from database. The trick is to keep the encoding scheme same all through.