Smart quotes do not display properly in email from phpmailer

I am dealing with a LAMP web server. I have forms that users use to submit text that is stored in a text box in mysql. Often this text is copied and pasted from Microsoft Office products, so I get a lot of smart quotes and emdash. These characters display correctly if I retrieve them from the database and display them on a web page, but where I encounter a problem, you send the text via email using the phpmailer class. I get stuff that looks like this: "(where should it be emdash).

One thing that may be important: if I pulled out the console in mysql and select a field that has emdash or a smart quote, it will not display correctly on my console: - as above if my php page (using PDO) selects field and displays it, it will be displayed correctly in the browser (in this case emdash).

I'm not sure if there is a way to select the character set in phpmailer (maybe this is a simple setup somewhere?) Or if there is a better way to solve this problem. I think it should be clear to me that “finding and replacing smart quotes and emdash with their usual equivalents” is NOT the answer I'm looking for (hopefully this is not the only solution).

I found this information:
My php webpage: utf-8
mysql client encoding: latin1
mysql server encoding: latin1
phpmailer character set: iso-8859-1

+3
source share
2 answers

The character set can be included in phpmailer with the following code:

$myMail->CharSet  = "UTF-8";

This solved my problem. Typical quotation marks and double dashes appear in my phpmailer emails as expected now. Perhaps this was a noobish sorting question (blush). Thank you, Colonel Shrapnel, for prompting me to think about what encoding all parts of the puzzle used. I will vote for you, but I have no reputation.

, , :
http://www.joelonsoftware.com/articles/Unicode.html

+3

Source: https://habr.com/ru/post/1781503/


All Articles