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 クレメンツサイモン).
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'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 クレメンツサイモン).
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]