Link to home
Start Free TrialLog in
Avatar of bassNsnare
bassNsnare

asked on

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

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
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

For reference : https://www.experts-exchange.com/questions/23695653/sending-arabic-mail-with-PHP.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"

Avatar of bassNsnare
bassNsnare

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Well done.