Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > sendmail unicode problem

Reply
Thread Tools

sendmail unicode problem

 
 
Supra
Guest
Posts: n/a
 
      07-14-2008
Hi,

I'm using the following code to send an email from a form on a PHP page. If
there're unicode characters in message body, they get carried over fine in
the email sent out, however if there are some in the subject or name fields,
they come out as blanks in the email received. Does anyone know how this can
be fixed?

#!/usr/bin/perl

print "Content-Type: text/html\n\n";

use utf8;
use CGI;
$q = new CGI;

unless(open (MAIL, "|/usr/lib/sendmail -t"))
{
warn "Error starting sendmail: $!";
}
else
{
print MAIL "Content-type: text/html\;charset=UTF-8\n";
print MAIL "From: ".$q->param('mail_name')."
<".$q->param('mail_from').">\n";
print MAIL "To: name\@email.com\n" ;
print MAIL "Subject: ".$q->param('mail_subject')."\n\n";
print MAIL $q->param('mail_body');
close(MAIL) || warn "Error closing mail: $!";
}

Many thanks,

Julius



 
Reply With Quote
 
 
 
 
Andrzej Adam Filip
Guest
Posts: n/a
 
      07-14-2008
"Supra" <(E-Mail Removed)> wrote:
> I'm using the following code to send an email from a form on a PHP page. If
> there're unicode characters in message body, they get carried over fine in
> the email sent out, however if there are some in the subject or name fields,
> they come out as blanks in the email received. Does anyone know how this can
> be fixed?
>
> #!/usr/bin/perl
>
> print "Content-Type: text/html\n\n";
>
> use utf8;
> use CGI;
> $q = new CGI;
>
> unless(open (MAIL, "|/usr/lib/sendmail -t"))
> {
> warn "Error starting sendmail: $!";
> }
> else
> {
> print MAIL "Content-type: text/html\;charset=UTF-8\n";
> print MAIL "From: ".$q->param('mail_name')."
> <".$q->param('mail_from').">\n";
> print MAIL "To: name\@email.com\n" ;
> print MAIL "Subject: ".$q->param('mail_subject')."\n\n";
> print MAIL $q->param('mail_body');
> close(MAIL) || warn "Error closing mail: $!";
> }


1) Non USASCII characters *in headers* require special encoding:

use Encode;

$x="....";
$x_for_header = Encode::encode('MIME-Q', $x);

MIME-Q is the best for mostly USASCII strings
MIME-B is the best for mostly non USASCII strings

2) Add one extra header to *fully* declare body encoding:
print MAIL "Content-Transfer-Encoding: 8bit\n";

--
[pl>en Andrew] Andrzej Adam Filip : http://www.velocityreviews.com/forums/(E-Mail Removed) : (E-Mail Removed)
Whenever I date a guy, I think, is this the man I want my children
to spend their weekends with?
-- Rita Rudner
 
Reply With Quote
 
 
 
 
Andrzej Adam Filip
Guest
Posts: n/a
 
      07-14-2008
"Supra" <(E-Mail Removed)> wrote:
> I'm using the following code to send an email from a form on a PHP page. If
> there're unicode characters in message body, they get carried over fine in
> the email sent out, however if there are some in the subject or name fields,
> they come out as blanks in the email received. Does anyone know how this can
> be fixed?
>
> #!/usr/bin/perl
>
> print "Content-Type: text/html\n\n";
>
> use utf8;
> use CGI;
> $q = new CGI;
>
> unless(open (MAIL, "|/usr/lib/sendmail -t"))
> {
> warn "Error starting sendmail: $!";
> }
> else
> {
> print MAIL "Content-type: text/html\;charset=UTF-8\n";
> print MAIL "From: ".$q->param('mail_name')."
> <".$q->param('mail_from').">\n";
> print MAIL "To: name\@email.com\n" ;
> print MAIL "Subject: ".$q->param('mail_subject')."\n\n";
> print MAIL $q->param('mail_body');
> close(MAIL) || warn "Error closing mail: $!";
> }


1) Non USASCII characters *in headers* require special encoding:

use Encode;

$x="....";
$x_for_header = Encode::encode('MIME-Q', $x);

MIME-Q is the best for mostly USASCII strings
MIME-B is the best for mostly non USASCII strings

2) Add one extra header to *fully* declare body encoding:
print MAIL "Content-Transfer-Encoding: 8bit\n";

--
[pl>en Andrew] Andrzej Adam Filip : (E-Mail Removed) : (E-Mail Removed)
Whenever I date a guy, I think, is this the man I want my children
to spend their weekends with?
-- Rita Rudner
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      07-14-2008
"Supra" <(E-Mail Removed)> wrote:
>I'm using the following code to send an email from a form on a PHP page. If
>there're unicode characters in message body, they get carried over fine in
>the email sent out, however if there are some in the subject or name fields,
>they come out as blanks in the email received. Does anyone know how this can
>be fixed?


Are you saying that the only characters that are displayed properly are
non-Unicode characters? That's odd to say the least! I would have
assumed that non-Unicode makes even more trouble then Unicode. Also, out
of curiosity, how did you test that the non-Unicode characters are
displayed properly?

I am a bit rusty on email, but Unicode and email used to be a rather
poor combination. Most email clients don't (didn't?) handle Unicode at
all and I have a vague memory that even the standard didn't allow
Unicode in the header fields.
At the end we had to send email in a different target encoding for each
locale because there was just no way to find a common denominator. This
was the one big exception to "use Unicode, dude".

jue
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      07-14-2008
"Supra" <(E-Mail Removed)> wrote:
>I'm using the following code to send an email from a form on a PHP page. If
>there're unicode characters in message body, they get carried over fine in
>the email sent out, however if there are some in the subject or name fields,
>they come out as blanks in the email received. Does anyone know how this can
>be fixed?


Are you saying that the only characters that are displayed properly are
non-Unicode characters? That's odd to say the least! I would have
assumed that non-Unicode makes even more trouble then Unicode. Also, out
of curiosity, how did you test that the non-Unicode characters are
displayed properly?

I am a bit rusty on email, but Unicode and email used to be a rather
poor combination. Most email clients don't (didn't?) handle Unicode at
all and I have a vague memory that even the standard didn't allow
Unicode in the header fields.
At the end we had to send email in a different target encoding for each
locale because there was just no way to find a common denominator. This
was the one big exception to "use Unicode, dude".

jue
 
Reply With Quote
 
Supra
Guest
Posts: n/a
 
      07-15-2008
"Andrzej Adam Filip" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Supra" <(E-Mail Removed)> wrote:
>> I'm using the following code to send an email from a form on a PHP page.
>> If
>> there're unicode characters in message body, they get carried over fine
>> in
>> the email sent out, however if there are some in the subject or name
>> fields,
>> they come out as blanks in the email received. Does anyone know how this
>> can
>> be fixed?
>>
>> #!/usr/bin/perl
>>
>> print "Content-Type: text/html\n\n";
>>
>> use utf8;
>> use CGI;
>> $q = new CGI;
>>
>> unless(open (MAIL, "|/usr/lib/sendmail -t"))
>> {
>> warn "Error starting sendmail: $!";
>> }
>> else
>> {
>> print MAIL "Content-type: text/html\;charset=UTF-8\n";
>> print MAIL "From: ".$q->param('mail_name')."
>> <".$q->param('mail_from').">\n";
>> print MAIL "To: name\@email.com\n" ;
>> print MAIL "Subject: ".$q->param('mail_subject')."\n\n";
>> print MAIL $q->param('mail_body');
>> close(MAIL) || warn "Error closing mail: $!";
>> }

>
> 1) Non USASCII characters *in headers* require special encoding:
>
> use Encode;
>
> $x="....";
> $x_for_header = Encode::encode('MIME-Q', $x);
>
> MIME-Q is the best for mostly USASCII strings
> MIME-B is the best for mostly non USASCII strings
>
> 2) Add one extra header to *fully* declare body encoding:
> print MAIL "Content-Transfer-Encoding: 8bit\n";
>
> --
> [pl>en Andrew] Andrzej Adam Filip : (E-Mail Removed) : (E-Mail Removed)
> Whenever I date a guy, I think, is this the man I want my children
> to spend their weekends with?
> -- Rita Rudner


Hi Andrzej, thank you very much! You're a star!!!


 
Reply With Quote
 
Supra
Guest
Posts: n/a
 
      07-15-2008
"Andrzej Adam Filip" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Supra" <(E-Mail Removed)> wrote:
>> I'm using the following code to send an email from a form on a PHP page.
>> If
>> there're unicode characters in message body, they get carried over fine
>> in
>> the email sent out, however if there are some in the subject or name
>> fields,
>> they come out as blanks in the email received. Does anyone know how this
>> can
>> be fixed?
>>
>> #!/usr/bin/perl
>>
>> print "Content-Type: text/html\n\n";
>>
>> use utf8;
>> use CGI;
>> $q = new CGI;
>>
>> unless(open (MAIL, "|/usr/lib/sendmail -t"))
>> {
>> warn "Error starting sendmail: $!";
>> }
>> else
>> {
>> print MAIL "Content-type: text/html\;charset=UTF-8\n";
>> print MAIL "From: ".$q->param('mail_name')."
>> <".$q->param('mail_from').">\n";
>> print MAIL "To: name\@email.com\n" ;
>> print MAIL "Subject: ".$q->param('mail_subject')."\n\n";
>> print MAIL $q->param('mail_body');
>> close(MAIL) || warn "Error closing mail: $!";
>> }

>
> 1) Non USASCII characters *in headers* require special encoding:
>
> use Encode;
>
> $x="....";
> $x_for_header = Encode::encode('MIME-Q', $x);
>
> MIME-Q is the best for mostly USASCII strings
> MIME-B is the best for mostly non USASCII strings
>
> 2) Add one extra header to *fully* declare body encoding:
> print MAIL "Content-Transfer-Encoding: 8bit\n";
>
> --
> [pl>en Andrew] Andrzej Adam Filip : (E-Mail Removed) : (E-Mail Removed)
> Whenever I date a guy, I think, is this the man I want my children
> to spend their weekends with?
> -- Rita Rudner


Hi Andrzej, thank you very much! You're a star!!!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer] Andrzej Adam Filip Perl 0 03-31-2008 09:24 PM
Unable to load tag handler class "com.cj.smtp.Sendmail" for tag "send:Sendmail" sugapablo Java 0 09-21-2007 01:41 PM
sending asp.net smtp sendMail of UTF-8 unicode contents peterson ASP .Net 0 12-30-2003 09:14 AM
Sendmail problem jim Perl 4 10-30-2003 06:29 PM



Advertisments