473,789 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to send subject in chinese using mail()

3 New Member
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 11455
clai83
41 New Member
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@exampl e.com';
$subject = 'some chinese text'
//this is the encoded subject;
$encoded_subjec t = "=?$charset?B?" .base64_encode( $subject)."?=\n ";
$message = 'some chinese text';

//HEADERS
$header .= "X-Mailer: Whatever you want\n";
$header .= "Return-Path: <someperson@exa mple.com>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "From: Some Person <someperson@exa mple.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={$chars et}\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_subjec t, $message, $header)) {
echo "Error: Message not sent";
}
else {
echo "Message sent successfully!";
};
?>
[/PHP]

The main answer to your question lies in the $encoded_subjec t 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
rathour
5 New Member
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 New Member
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
serena9131
3 New Member
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@exampl e.com';
$subject = 'some chinese text'
//this is the encoded subject;
$encoded_subjec t = "=?$charset?B?" .base64_encode( $subject)."?=\n ";
$message = 'some chinese text';

//HEADERS
$header .= "X-Mailer: Whatever you want\n";
$header .= "Return-Path: <someperson@exa mple.com>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "From: Some Person <someperson@exa mple.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={$chars et}\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_subjec t, $message, $header)) {
echo "Error: Message not sent";
}
else {
echo "Message sent successfully!";
};
?>
[/PHP]

The main answer to your question lies in the $encoded_subjec t 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 New Member
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
9876
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 ********************************** package Celcom.Client;
15
3318
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. <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function isPPC() { if (navigator.appVersion.indexOf("PPC") != -1) return true; else return false;
6
3263
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 my customers are not really happy with having the IIS installed, not being used except to send e-mail this is becoming a problem. I have also tried using a little program from code project for sending e-mail which works great on older servers...
1
2172
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
4559
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 windows application it worked fine, however I need to use a service as I don't want to rely on a user being logged in. The errors I get are: Index #:System.Web.HttpException: Could not access 'CDO.Message' object. --->...
2
5636
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 support .asp,.aspx files, it supports PHP files, I'm searching in JavaScript ,but not found any matter, I'don't Know PHP.I'm having lot of pressure of higer officials.Please help me on this.
6
6899
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 people and user should be able choose the check boxes to whom they want to send e mail to. I write some code simple If else conditions but i think i am making some mistakes. Because when i tried - it is not sending them e mails. Here is my code. I...
1
6574
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 specifies for each record... Essentially this is a make shift Ordering Tool and I want to be able to notify the receiver of the order and its specifics. q_Order_Detail_4email consists of ,,, and Example: Hello@mail.com,956,Modem,1000,xyz123...
0
1815
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 content. The content can display correctly but the To: From: and Subject become "???" after transfer. Is there any way to resolve this? Thanks. Below please find the code to send email. Dim iMsg Set iMsg = server.CreateObject("CDO.Message")
0
10374
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10121
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
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...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5404
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2898
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.