Hi Monks,
I am trying to send a mail in Chinese, using Net::SMTP. All the Chinese is in UTF-8 format, so I don't need a special encoding. It's enough to add "charset=utf-8" and the body of the mail is sent correctly (example below).
The problem is that although the body is sent correctly, the subject doesn't known that it is supposed to be in utf-8.
If you run the code below, you should get a mail with malformed letters in the subject and perfect Chinese in the body
#!/usr/bin/perl use strict; use warnings; use Net::SMTP; my $SMTP_HOST = 'localhost'; my $from = 'aaa@hotmail.com'; my $to = 'bbb@gmail.com'; my $msg = "MIME-Version: 1.0\n" . "Content-Type: text/plain; charset=UTF-8\n" . "Content-Transfer-Encoding: 8bit\n" . "From: $from\n" . "To: $to\n" . "Date: Sun, 23 Mar 2008 15:47:22 +0200\n" ##the subject . "Subject: δΈ­εη©ζ΅δΈιθ΄­θεδΌ\n\n" ##the body ."δΈ­εη©ζ΅δΈιθ΄­θεδΌ\n"; #Creating the SMTP object my $smtp = Net::SMTP->new( $SMTP_HOST,'Debug' => 1); #Sending the data $smtp->mail($from); $smtp->recipient($to); $smtp->data ($msg); $smtp->quit;
Does anyone have any idea how I can "tell" the subject it is also under utf-8?
Thanks a lot,
Guy Naamati

P.S. For some reason the utf-8/Chinese characters get changed when you copy paste them to VI. If you have this problem you can first copy the chars to a notepad and then to VI.

"Happiness is a warm gun"
--John Lennon

In reply to Encoding Mail Subject by mrguy123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.