Solved

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

Posted on 2009-06-29
5
381 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
ID: 24744435
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
ID: 24745231
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
ID: 24745328
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
ID: 24795494
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
ID: 24795588
Well done.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP: concatenate query 13 45
is this a cms? 8 36
PHP get array item with custom id 4 25
.htaccess 5 22
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 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

23 Experts available now in Live!

Get 1:1 Help Now