473,387 Members | 1,864 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,387 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 11391
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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...

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.