Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Charset

Status
Not open for further replies.

uniopp

Technical User
Oct 7, 2001
152
JP
Hi,
I'm using a perl script that takes html form content and sends it via email using sendmail.
It works fine with English text but I can't get it to work with Japanese text.
I'm using Thunderbird and Outlook Express to receive mail and have no problem when receiving Japanese text from other sources so I'm assuming the problem is in my perl code.
I can input the Japanese text into the html form and send the form but when I receive it via email the text is jumbled characters and numbers (e.g クレメンツサイモ&#12531).
I read somewhere that sendmail uses a default English charset if nothing is specified so I tried adding the following line to my perl script but it doesn't make any difference (except that the charset I added is specified in the email message source) -
print MAIL "Content-type: text/plain charset=Shift-JIS\r\n";[/color red]
I've tried different variation of the above including another Japanese charset - iso-2022-jp.
Is there something else I need to include to make this work?
Thanks.
Simon.


PS. Following is the sub that sends the email -


sub send_email
{
# Build the 'from' address of the form: "name <email address>"

$from_name=($CONFIG{'Name'} . " <" . $CONFIG{'email'} . "> ");

open(MAIL,"|$SENDMAIL -t") || die "Can't open $mailprog!\n";

# Output the mail header

#I added the following line
print MAIL "Content-type: text/plain charset=Shift-JIS\r\n";

print MAIL "To: $TO\r\n";
print MAIL "From: $from_name\r\n";
print MAIL "Reply-To: $from_name\r\n";
print MAIL "Subject: $SUBJECT\r\n\n";

# Output the mail message header with the Local Date/Time

if ($INCLUDE_HEADER eq "Yes") {
print MAIL "---------------------------------------------------------------\n";
print MAIL " The following information was submitted by: \n";
print MAIL " $CONFIG{'Name'} on $date\n";
print MAIL " From: $ENV{HTTP_REFERER}\n";
print MAIL "---------------------------------------------------------------\n\n";
}

# Output the mail body
# Optionally Sort and Print the name and value pairs in FORM array

if ($SORT_TYPE eq 'alphabetic')
{
foreach $key (sort keys %FORM)
{

print MAIL "$key: $FORM{$key}\n\n";
}
}
elsif ($SORT_TYPE eq 'field')
{
foreach $SORT_FIELD (@SORT_FIELDS)
{
if ($FORM{$SORT_FIELD})
{
print MAIL "$SORT_FIELD: $FORM{$SORT_FIELD}\n\n";
}
}
}
else
{
foreach $key (keys %FORM)
{
print MAIL "$key: $FORM{$key}\n\n";
}
}

# Output the mail footer

if ($INCLUDE_ENV_INFO eq "Yes") {
print MAIL "<REMOTE HOST> $ENV{'REMOTE_HOST'}\n";
print MAIL "<REMOTE ADDRESS> $ENV{'REMOTE_ADDR'}\n";
print MAIL "<USER AGENT> $ENV{'HTTP_USER_AGENT'}\r\n";
}

# Close the pipe and send the mail

close(MAIL);
} [/color red]
 
I think this is one of those times you are falling foul of the Unicode problem. If you are using anything before Perl 5.8, you'll need to use the utf8 module (1)

(1)
If you're able to upgrade to 5.8.4 or higher, then the Unicode support is better handle within the interpreter itself.

Barbie
Leader of Birmingham Perl Mongers
 
Hi Barbie,
I changed the charset to UTF-8 and it works -
Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top