Gossamer Forum
Home : General : Perl Programming :

Sendmail Charset

Quote Reply
Sendmail Charset
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";
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);
}
Quote Reply
Re: [jai] Sendmail Charset In reply to
Hi,

I believe you need to use text/html encoding to make &'1234; type charachters show up.

Example;

print MAIL "Content-type: text/html charset=UTF-8\r\n";

Not sure if thats your problem... but it may help :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sendmail Charset In reply to
Thanks Andy !!!!
That did the trick.
I'm wondering if it's going to matter what kind of OS or browser the user has or won't it matter?
(e.g I know Win XP and newer browsers have Unicode support but I'm not sure about older/other OS and browsers).
Can you see any potential problems?
Thanks.
Simon.
Quote Reply
Re: [jai] Sendmail Charset In reply to
Hi,

Glad it worked :)

UTF-8 is a generic charset, so most charachters should work with it.

Regarding cross-compatability, I don't think you will have any problems. In the early days, when different charsets were not so widely used, then you may have had a problem. In this day and age though, I don't know of anyone who isn't using a machine/browser capable of using different charsets Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sendmail Charset In reply to
Andy,

Let me tell you, that my e-mail client doesn't know UTF-8,
so I hate UTF-8 emails...

So yes, there are still some people, who doesn't like to use UTF-8.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...