473,793 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php mail() not sending chinese text correctly

72 New Member
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 6622
Markus
6,050 Recognized Expert Expert
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
dragon52
72 New Member
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 Recognized Expert Moderator Expert
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
dragon52
72 New Member
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
2156
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 the address http://babelfish.altavista.com/babelfish/trurl_pagecontent?url=http://www.etantonio.it/en/index.aspx&lp=en_zh into the browser the page he comes shown correctly in Chinese, if i save it and put it in my site and with the same below...
8
11990
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 part of a datagrid. When an input textbox is displayed it does not display chinese characters, but rather the unicode characters stored in the mssql 2000 server backend.
1
3119
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: - Setting the charset, codepage of the page - changed the responseEncoding in web.config to Big5 - hardcoded Response.ContentEncoding to 950 (codepage of Big5) - Change the file encoding to Big5 (in save option) None of them work.
0
2139
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 part of the email with something else. Looking at the server sent email source, the hacked emails have the following: This is a multi-part message in MIME format. ------=_NextPart_000_0001_01C60610.91D1FFA0 Content-Type: text/plain;...
34
18275
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 "127.0.0.1". 4. Authentication: "Anonymous access" only. 5. Outbound connection listen to TCP 25. Besides,
19
11244
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 happen, and how can I send it right ? I'm using vb.net 2005 express with framework 2.0 Thanks for an answear ...
0
1287
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 purpose I also installed a copy of Chinese Star software in my development machine, so I can correctly renders the doc correctly. Ussually I just copy the text from the original DOC file they supplied, and paste it onto a blank ASP.NET page.
0
1257
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 purpose I also installed a copy of Chinese Star software in my development machine, so I can correctly renders the doc correctly. Ussually I just copy the text from the original DOC file they supplied, and paste it onto a blank ASP.NET page.
5
8562
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 I can type characters into this box no problem. They display correctly. I can also copy and paste Chinese characters from web sites into this text box and they display no problem. Here is my problem. If I put some Chinese characters in the...
0
9670
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.