Solved

How do I ensure that all Chinese characters show up in an HTML email sent via PHP?

Posted on 2009-06-29
5
379 Views
Last Modified: 2013-12-13
I have a contact form on a Website I built, and I've just been made aware that there may be users submitting Chinese characters through the form. I've encoded each page in the process as UTF-8, but I'm still having problems. I put normal special characters (i.e. letters with accents) in one field and it came through in the email correctly (for me anyway, my colleague just informed me that any special characters in the email I sent to him were garbled).

A field I submitted with a block of Chinese text (*‚Œ      ¹zÉÛÒ”¹FmÒkk]/¹       *Øö4) came back to me as this:

*?z,O?,z ?>>'"-?. f'..]~ ,4

Now, who knows if these characters are going to show up correctly after submitting this form, so I'm going to attach a screen shot.

Me and my colleague are both using Outlook to receive email.

Please see code snippet. $form array values are equal to the PHP $_POST array.

NOTE: I'm using CDO to send the email, I can post my code for that if need be.
echo "<tr style='font-size:12px;'><td valign='top' width='30%' style='border:1px solid #ccc;padding:2px;'><strong>Name:</strong></td><td style='border:1px solid #ccc;padding:2px;'>" . $form['first_name'] . ' ' . $form['last_name'] . "</td></tr>";

            if($form['title'] !== ''){ 

                echo "<tr style='font-size:12px;'><td valign='top' style='border:1px solid #ccc;padding:2px;'><strong>Title:</strong></td><td style='border:1px solid #ccc;padding:2px;'>" . $form['title'] . "</td></tr>";

            }

Open in new window

email-char-prob.jpg
0
Comment
Question by:bassNsnare
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
For reference : http://www.experts-exchange.com/Software/Server_Software/Email_Servers/SendMail/Q_23695653.html?sfQueryTermInfo=1+beer+rquadling+unicode#22592127

Is EVERY process that working on the data capable of dealing with Unicode?

Relevant?

http://help.lockergnome.com/office2/CDO-mail-Unicode--ftopict764262.html

http://blogs.msdn.com/webdav_101/archive/2008/02/14/cdo-1-21-and-unicode-text-japanese-chinese-korean-etc.aspx

' Set the localid and codepage - this needs to be set BEFORE calling Logon
oSession.SetLocaleIDs CLng(1041), CLng(932)

Seems to be the most interesting part on that link.



http://support.microsoft.com/kb/813252 Hmmm. "CDO.Message Object that Contains Unicode Is Not Correctly Identified"

0
 

Author Comment

by:bassNsnare
Comment Utility
Could the fact that I'm copying and pasting the Chinese text from a site that may or may not be UTF-8 make a difference?

Thank you very much for linking that thread on here by the way, I learned a lot. Hopefully I'll be able to close this question shortly.
0
 
LVL 40

Accepted Solution

by:
RQuadling earned 250 total points
Comment Utility
That MAY be the case. It isn't easy to tell.

I would get a Chinese speaker to send you some simple phrases in a UTF-8 text file so you can cut and paste them.

0
 

Author Comment

by:bassNsnare
Comment Utility
I ended up having to switch back to using the "mail()" function and abandon CDO. Seems to be working fine now. Every file across the board is UTF-8, both with a charset, and with how I saved each file.


// Set parameters of the email

			$to = "test@test.com";

			$subject = "Test Chinese Submission";

			// To send HTML mail, the Content-type header must be set

			$headers  = 'MIME-Version: 1.0' . "\r\n";

			$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

			

			// Additional headers

			$headers .= 'Bcc: test1@test.com' . "\r\n";

			$headers .= 'From: test2@test.com' . "\r\n";
 

			

			// Mail function that sends the email.

			mail($to,$subject,$email,$headers);

Open in new window

0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Well done.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
Ransomware continues to be a growing problem for both personal and business users alike and Antivirus companies are still struggling to find a reliable way to protect you from this dangerous threat.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now