473,411 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

php mail() not sending chinese text correctly

Hi there,

I am writing php to send email containing Chinese text. The chinese displays correctly depending on different mail servers, it seems.

I can read the chinese text if I open the email using webmail on my telco's website (Telstra's Bigpond in Australia) or Yahoo mail. If I look at the same email using MS Outlook then the chinese text is just rubbish.

So I experimented and wrote (VS2008) the code using the Smtp.Client (Microsoft System.Net.Mail) rather then php. This method gives me the correct chinese text in both webmail and Outlook.

Can someone explain to me what is going on here?

Given I must use php, how do I reproduce smtp.client code in php?

In the php code below how much of the $Header stuff do I actually need?

Sorry for such a long winded question and thanks in advance.

Here is my codes, both php and c#

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $charset = "utf-8";
  3. $to = "$_POST[EmailAddress]";
  4. $subject = "Student Enrollment";
  5. $body = "尊敬的家 Welcome to the Sydney";
  6.  
  7. //HEADERS
  8. $header .= "X-Mailer: Whatever you want\n";
  9. $header .= "Return-Path: <someperson@example.com>\n";
  10. $header .= "MIME-Version: 1.0\n";
  11. $header .= "From:denis@yahoo.com.au\n";
  12. $header .= "X-Accept-Language: cn\n";
  13. $header .= "Content-Type: text/plain; charset={$charset}\n";
  14. $header .= "Content-Transfer-Encoding: 8bit\n";
  15.  
  16.     if (mail($to,$subject,$body,$header))
  17.     {
  18.         echo("<p>A confirmation email has been sent.</p>");
  19.     }
  20.     else
  21.     {
  22.         echo("<p>We are unable to send you an email.</p>");
  23.     }
  24. ?>
  25.  
  26. ////////////////////////////////
  27.  
  28.             MailMessage mail = new MailMessage();
  29.  
  30.             mail.From = new MailAddress("denis@yahoo.com.au");
  31.             mail.To.Add(address);
  32.             mail.Subject = subject;
  33.             mail.Body = body;
  34.  
  35.             SmtpClient smtp = new SmtpClient("mail.bigpond.com");
  36.             try
  37.             {
  38.                 smtp.Send(mail);
  39.             }
Sep 19 '09 #1
4 6565
Markus
6,050 Expert 4TB
I suspect this is because of PHP's lax handling of Unicode characters. You might try out PHP6 as one of it's main goals is to improve multi-byte and unicode character support.


Mark.
Sep 19 '09 #2
Mark,

Thanks very much for your response.

Unfortunately I don't control what version of php to use.

Since Smtp.Client in the .Net environment works do you think it will work if I write the php using smtp?

I know hardly anything about smtp. I have searched the net about smtp in php and what I have found mentions changing the configuration and seem complicated.

Can you point me to some smtp code which I can use fairly easily?

Thanks
Denis
Sep 19 '09 #3
Dormilich
8,658 Expert Mod 8TB
a fairly easy (to use and well documented) PHP Mail Script is SwiftMailer, though I didn’t try sending chinese text with it.
Sep 19 '09 #4
Thanks Dormilich.

SwiftMailer looks interesting. I will have a look.
Sep 20 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Antonio | last post by:
With the following page aspx I try to translate one my page from English to Chinese, using UTF8, the result Is that the Chinese characters do not come read correctly, if instead I insert directly...
8
by: pabv | last post by:
Hello all, I am having a few issues with encoding to chinese characters and perhaps someone might be able to assist. At the moment I am only able to see chinese characters when displayed as...
1
by: Jason Chan | last post by:
Some chinese characters data (in Big5 encoding) is stored in database. I tried to display the data in an aspx but the characters cannot display correctly. I tried anything I think is related: -...
0
by: nauticalmac | last post by:
I'm using CDO to send mail to the site owner from ASP pages with forms. Recently one of my forms is occasionally sending email with what seems to be an insertion which is replacing the plain text...
34
by: antonyliu2002 | last post by:
I've set up the virtual smtp server on my IIS 5.1 like so: 1. Assign IP address to "All Unassigned", and listen to port 25. 2. Access Connection granted to "127.0.0.1". 3. Relay only allow...
19
by: ... | last post by:
Hi I need to send a chr(255) to a serial port. When I send it, through comm.write (chr(255)) it sends a chr(63) ... in Hex, I write chr(&FF) and it actually sends chr(&3F) ... why does this...
0
by: Andy Lim | last post by:
Hi all, In my recent project, my client uses Chinese Star software to type the articles in chinese (using MS Word), and I need to display these articles within ASP.NET pages. And, for this very...
0
by: Andy Lim | last post by:
Hi all, In my recent project, my client uses Chinese Star software to type the articles in chinese (using MS Word), and I need to display these articles within ASP.NET pages. And, for this very...
5
by: Figmo | last post by:
I'm having a problem working with foreign characters (well....foreign to me anyway) I have a textbox control on a form. The font is set to MS Arial Unicode. If I use the Chinese input method...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.