in reply to Re^3: Problem with russian / cyrillic in e-mail program.
in thread Problem with russian / cyrillic in e-mail program.

Sorry for being vague. This is what I tried, thought it would work this way but it didn't. Wasn't sure what charset to use either.

sub send_info { # Adjust sender, recipient and your SMTP mailhost use MIME::Base64; my $charset = 'x-mac-cyrillic'; my $from_address = $from; my $to_address = $infoemail; # Adjust subject and body message my $message_body = "<h2>The following visitor requested informatio +n.</h2><b>Name:</b> $string<br><b>E-mail:</b> $email<br>"; my $subject = "$string is requesting information."; my $subject = "=?$charset?B?".encode_base64($subject)."?="; # Create the multipart container my $msg = MIME::Lite->new ( From => $from_address, To => $to_address, BCC => $bcc, Subject => $subject, Type =>'multipart/mixed' ) or die "Error creating multipart cont +ainer: $!\n"; # Add the text message part $msg->attach ( Type => 'text/html', Data => qq{ $message_body } ) or die "Error adding the text message part: $!\n"; # Now send $msg->send("sendmail") or die "Error e-mailing: $!\n";

Replies are listed 'Best First'.
Re^5: Problem with russian / cyrillic in e-mail program.
by Corion (Patriarch) on Apr 04, 2010 at 08:04 UTC

    On first glance, this looks OK, but then, you don't tell me what's wrong with it.

    On what character set to use - I don't know. You need to know what character set your strings are in. That's the characterset you then use. Common charsets are UTF-8 , or maybe for cyrillic KOI-8.

      First of all, thank you for being patient with a dumby. Moving along, I am pulling text from this site http://www.mindmachine.ru/ to test with. I have tried now UTF-8, KOI-8, windows-1251

      I'm assuming that it's perfectly normal for the body of the e-mail to be fine while at the same time the subject be mangled.

      Here's what's wrong with it: Screenshot

        Your string is (HTML) entity-encoded (which you would have also seen by printing it. Either that's this webmail hoster doing this, or it is your program which sends it. I really wonder why you are trying to send email without knowing what your text is in. And why you are scraping the text content from some external web site.

        So, your first step would be to make sure you know what encoding your subject string is in. If it is HTML entities, then HTML::Entities::decode can turn that into an UTF-8 string, which you can then in turn Base64-encode for the MIME subject header. But in reality, it would be much better to eliminate the HTML part of the equation and directly set the subject to some well-known characters in a well-known encoding yourself directly, for example by using:

        my $subject = 'Hello World';

        except using cyrillic charset, potentially in utf8 or KOI-8:

        use utf8; my $subject = 'Hello World'; # except in cyrillic

        or

        use Encoding 'KOI-8'; my $subject = 'Hello World'; # except in cyrillic

        if your source code editor supports KOI-8.

        The screenshoot looks like a webmail client that can't properly handle Unicode (i.e. not your fault). Try using a "real" mail user agent instead, e.g. Thunderbird.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)