Solved

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

Posted on 2009-06-29
5
383 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
PHP contact form that lets the user to contact the company through email contact form. A button is fixed at the bottom of site, on clicking a new window will open where a user can send the email.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
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: …

770 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