stonemen has asked for the wisdom of the Perl Monks concerning the following question:
I want this snippet to send email contents in Japanese. What do I do? Many thanks for any help. Jim
# Open The Mail Program
open(MAIL,"|$mailprog -t");
print MAIL "To: $FORM{'tomail'}\n";
print MAIL "From: $FORM{'frommail'} ($FORM{'fromname'})\n";
print MAIL "Subject: $FORM{'subject'}\n\n";
print MAIL "Hi $FORM{'toname'}!\n\n";
print MAIL $FORM{'message'};
print MAIL "\n\n";
print MAIL "Regards,\n\n";
print MAIL "$FORM{'fromname'}\n\n";
close (MAIL);
2002-01-01 Edit by Corion : Added code tags
Re: cgi email Japanese contents scripting problem
by mpolo (Chaplain) on Jan 01, 2002 at 14:19 UTC
|
I think you're going to have to delve into the world of MIME in order to get this correctly encoded. If you send mail without any indications, it automatically gets considered as text/plain, which would prevent correct interpretation of the Japanese characters.
Try MIME::Lite or MIME-tools. (The docs talk mostly about European "funny characters", but I imagine you should be able to make it work for other encoding schemes.) | [reply] |
|
Hi,
Thanks for taking the time to think about and respond to my inquiry.
I believe you are correct about the header which perhaps should have something like:
content-transfer-encoding ISO-2022-JP
and also perhaps
content-type xxsomething
There are several problems here:
1. I don't know perl programming, so I don't know what or where to put { }; etc.
2. And, then where do these lines go in the script?
I apologize for trying to get an easy solution to this problem.
Regards,
Jim
| [reply] |
|
No problem. First the obligatory point. If you value the security of your web site, it is much better to use CPAN modules like CGI.pm to handle your CGI needs, something like Mail::Sendmail to handle the mailing, and something like MIME::Lite to create a nice MIME packet.
Right now though, you're trying to get something to work and probably won't be willing to wade through all that. So as an interim workaround, I would suggest inserting into the part of the program that prints out the Header (The first group of print MAIL "....."; (up to print MAIL "\n\n", which ends the header) the following (not tested, as I don't know Japanese...)
print MAIL "Content-Transfer-Encoding: ISO-2022-JP\n";
print MAIL "Content-Type: text/plain\n";
But be careful with this! You are taking input that the user has input onto a webform and then blithely sending it out to an external program (usually sendmail). Someone who knows you were doing that could try sending a code to end the sendmail input followed by a command to do something nasty to your server.
If you use Super Search you should be able to get a lot of information about CGI security and see how to patch this up better. Or, for an easier way, davorg, one of our resident monks, and the London Perl Mongers are working on easy programs to allow you to set this kind of thing up without giving away all the security. Look for it here: nms. | [reply] [d/l] |
Re: cgi email Japanese contents scripting problem
by bladx (Chaplain) on Jan 01, 2002 at 10:03 UTC
|
Well I have not ever researched this subject of sending Japanese via email really before, I cannot essentially answer your question. I can, however, point you in the direction of your new friend (since you seem like a new user here at the Monastery,)super_search!
I typed in a search for this type of question, and came up with a topic that was asked in the past that might help a little bit on this topic, it was Pyuuta: Programming in Japanese.
If I were you, I would search on the topic of Perl and Unicode programming. This might help you to figure out how to achieve what you are asking.
Hope this helps you somewhat ...
Andy Summers | [reply] |
Re: cgi email Japanese contents scripting problem
by lestrrat (Deacon) on Jan 01, 2002 at 10:11 UTC
|
I don't know about convetions, rfcs and stuff, but our
system always needs to first change the character
encoding to jis, and then add these headers:
Content-Type: text/plain; charset=ISO-2022-JP
Content-Transfer-Encoding: 7bit
Maybe that's what you need to do? | [reply] [d/l] |
Re: cgi email Japanese contents scripting problem
by Hanamaki (Chaplain) on Jan 02, 2002 at 01:36 UTC
|
Yes, as said above sending email in Japanese usually means sending the
the text (7-bit) jis-encoded.
(1) Before you can do this you need to find out it which
encoding your programm receives the data.This could be
jis, shift-jis, euc-jp or Unicode. You can find out the encoding
with the Jcode
module from CPAN:
use Jcode;
my $encoding = getcode($content);
(2) After you have found out the encoding you want to convert
your string to 7 bit jis.
my $mailtext = Jcode::convert($content, "jis", $encoding);
Appart from that, the Jcode module also supplies some
basic MIME handling functions.
Hope that helps,
Hanamaki
| [reply] [d/l] [select] |
|
Thanks for all the help.
Hanamaki san,
In my script, is the format for your coding:
PRINT MAIL "my $mailtext = Jcode::convert($content, "jis", $encoding)";
Thanks,
Jim
| [reply] |
|
|