sendmail unicode problem

Discussion in 'Perl' started by Supra, Jul 14, 2008.

  1. Supra

    Supra Guest

    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
    Supra, Jul 14, 2008
    #1
    1. Advertising

  2. "Supra" <> 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 : :
    Whenever I date a guy, I think, is this the man I want my children
    to spend their weekends with?
    -- Rita Rudner
    Andrzej Adam Filip, Jul 14, 2008
    #2
    1. Advertising

  3. "Supra" <> 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 : :
    Whenever I date a guy, I think, is this the man I want my children
    to spend their weekends with?
    -- Rita Rudner
    Andrzej Adam Filip, Jul 14, 2008
    #3
  4. "Supra" <> 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
    Jürgen Exner, Jul 14, 2008
    #4
  5. "Supra" <> 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
    Jürgen Exner, Jul 14, 2008
    #5
  6. Supra

    Supra Guest

    "Andrzej Adam Filip" <> wrote in message
    news:...
    > "Supra" <> 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 : :
    > 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!!!
    Supra, Jul 15, 2008
    #6
  7. Supra

    Supra Guest

    "Andrzej Adam Filip" <> wrote in message
    news:...
    > "Supra" <> 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 : :
    > 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!!!
    Supra, Jul 15, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jim

    Sendmail problem

    jim, Oct 24, 2003, in forum: Perl
    Replies:
    4
    Views:
    642
  2. peterson
    Replies:
    0
    Views:
    703
    peterson
    Dec 30, 2003
  3. Andrea Williams

    Urgent SendMail Problem

    Andrea Williams, Dec 9, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    1,852
    Andrea Williams
    Dec 13, 2004
  4. sugapablo
    Replies:
    0
    Views:
    2,141
    sugapablo
    Sep 21, 2007
  5. Andrzej Adam Filip
    Replies:
    0
    Views:
    4,060
    Andrzej Adam Filip
    Mar 31, 2008
Loading...

Share This Page