473,396 Members | 1,771 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,396 software developers and data experts.

How to send subject in chinese using mail()

Dear all,

I having problem for sending subject in cheses language using mail(), Can anyone let me know how to send send non unicode subject ?


Thanks
Serena
Dec 7 '07 #1
5 11394
clai83
41
Dear all,

I having problem for sending subject in cheses language using mail(), Can anyone let me know how to send send non unicode subject ?


Thanks
Serena

Did you try changing the header of the message when using the mail() function?

I found some information at PHP.net under the mail section.

Mail header fields and subject allow only ascii characters. You have to encode the subject line to ascii characters from your encoding yourself. You can use Quoted prinables "Q", or "B" base64.

Base64 is easier, and PHP has a built in function

[PHP]
<?php
//specify a character set
$charset = "GB2312";
$to = 'example@example.com';
$subject = 'some chinese text'
//this is the encoded subject;
$encoded_subject = "=?$charset?B?".base64_encode($subject)."?=\n" ;
$message = 'some chinese text';

//HEADERS
$header .= "X-Mailer: Whatever you want\n";
$header .= "Return-Path: <someperson@example.com>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "From: Some Person <someperson@example.com>\n";

//I believe that language code for chinese is cn
$header .= "X-Accept-Language: cn\n";

//This header should make sure that the message has a Guobiao
//encoding
$header .= "Content-Type: text/plain; charset={$charset}\n";

//I'm not an expert, but depending on the character set you use
//you may want to change the transfer encoding.
//I found that GB2312 is 7 bit, so I believe you can
//leave this header out. If you choose another encoding
//make sure the transfer encoding is correct.
//$header .= "Content-Transfer-Encoding: 8bit\n";

//Print error if mail doesn't work, otherwise print successful message
if(!mail($to, $encoded_subject, $message, $header)) {
echo "Error: Message not sent";
}
else {
echo "Message sent successfully!";
};
?>
[/PHP]

The main answer to your question lies in the $encoded_subject variable.

=?$charset?B?".base64_encode($subject)."?=\n

Just specify the character set you want and use the base64_encode function to encode your $subject.

I do a lot of Japanese pages, and I tested a similar version of this script with a japanese encoding and it came out fine.

Hopefully this helps, and let me know if it works
Dec 9 '07 #2
try changing the charset to utf-8 of your web page

and a better method i personally feel is that
Ms. Frontpage provides better grip in unicode than dreamweaver.
Dec 10 '07 #3
clai83
41
try changing the charset to utf-8 of your web page

and a better method i personally feel is that
Ms. Frontpage provides better grip in unicode than dreamweaver.
Did the person ask how to send a NON unicode subject? Changing the character set of the web page won't really do anything in this case. And I'm not really sure if we are even talking about a webpage either. We are talking about the mail() function.

Anyhow all email headers must be made up of characters of the ascii character set. Chinese is not a part of that character set, thus you have to use a work around for all headers that you need to be Chinese or any language other than English for that matter.

Of course doing everything in unicode is much easier because you only have to worry about one character set. It's getting there.
Dec 10 '07 #4
Thanks, but i got error as below

Warning: mail(): Bad parameters to mail() function, mail not sent. in /home/content/s/e/r/serena9131/html/test_send6.php on line 31










I found some information at PHP.net under the mail section.

Mail header fields and subject allow only ascii characters. You have to encode the subject line to ascii characters from your encoding yourself. You can use Quoted prinables "Q", or "B" base64.

Base64 is easier, and PHP has a built in function

[PHP]
<?php
//specify a character set
$charset = "GB2312";
$to = 'example@example.com';
$subject = 'some chinese text'
//this is the encoded subject;
$encoded_subject = "=?$charset?B?".base64_encode($subject)."?=\n" ;
$message = 'some chinese text';

//HEADERS
$header .= "X-Mailer: Whatever you want\n";
$header .= "Return-Path: <someperson@example.com>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "From: Some Person <someperson@example.com>\n";

//I believe that language code for chinese is cn
$header .= "X-Accept-Language: cn\n";

//This header should make sure that the message has a Guobiao
//encoding
$header .= "Content-Type: text/plain; charset={$charset}\n";

//I'm not an expert, but depending on the character set you use
//you may want to change the transfer encoding.
//I found that GB2312 is 7 bit, so I believe you can
//leave this header out. If you choose another encoding
//make sure the transfer encoding is correct.
//$header .= "Content-Transfer-Encoding: 8bit\n";

//Print error if mail doesn't work, otherwise print successful message
if(!mail($to, $encoded_subject, $message, $header)) {
echo "Error: Message not sent";
}
else {
echo "Message sent successfully!";
};
?>
[/PHP]

The main answer to your question lies in the $encoded_subject variable.

=?$charset?B?".base64_encode($subject)."?=\n

Just specify the character set you want and use the base64_encode function to encode your $subject.

I do a lot of Japanese pages, and I tested a similar version of this script with a japanese encoding and it came out fine.

Hopefully this helps, and let me know if it works[/quote]
Dec 10 '07 #5
clai83
41
Thanks, but i got error as below

Warning: mail(): Bad parameters to mail() function, mail not sent. in /home/content/s/e/r/serena9131/html/test_send6.php on line 31
I had an error on my previous post on line 5 where I forgot a semi-colon, but other than that, I tested it and the code on the post works.

Please post the code you tried. The error says that you didn't put in the correct variables. Check if you put it in the correct order.
Dec 10 '07 #6

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

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
15
by: Steve Horrillo | last post by:
I can't figure out why this script won't insert the subject in the email and why can't I control the font and size being used? I'm not sure where to post this. Let me know where if this is OT. ...
6
by: John J. Hughes II | last post by:
I have a service that needs to send e-mail alerts. I have been attempting to use the System.Net.Mail function from .NET but this seems to require the IIS be installed and running. Since some of...
1
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
2
by: Malli mindwave | last post by:
Hi, We are using the yahoowebHostiing service for my company website, In that one screen of the SendComments/FeedBack section is there, I'm basically dot.net develeoper ,but yahoowebhosting not...
6
by: Harshpandya | last post by:
Hi all, I am working on the form in which you fill out the whole PHP form and e mail that details to someone. It is working fine. But now i want to send the same form to be sent to different...
1
by: sxwend | last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the results to just the email addresses that the query...
0
by: Chan Chi Man | last post by:
Hello all, I am using ASP + CDO tp send mail (running on Win2000 server and will not upgrade to use ASPX in 2 years time). I use ASP + CDO to send email with Chinese To:, From:, Subject: and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...

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.