Solved

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

Posted on 2009-06-29
5
385 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:Richard Quadling
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:
Richard Quadling 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:Richard Quadling
ID: 24795588
Well done.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Are you irritated by repeating emails issue in Microsoft Outlook 2016 after recent update ?  Lets’ see how to resolve and prevent duplicate emails in the Outlook 2016 using some simple techniques.
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…
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.

830 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