Search code examples
perldecodeencode

Perl utf8 decode and encode


I've got a situation here trying to send and email with Mail::Sendmail from Perl (cyrillic).

use Mail::Sendmail;
use Encode;
use utf8;

my $subject= "cyrillic message";
....

The problem is that I receive unrecogniseable symbols in my mail message.

I've already tried to use utf8, not to use utf8, I've tried decode and encode, decode_utf8 and so on (have read a lot, including Perlmonks discussions), but still I receive 2 types of unrecogniseable symbols in mails' subject or "Wide character in subroutine entry".

Added:

#!/usr/bin/perl

use Mail::Sendmail;
use Encode;
use utf8;
use warnings;

my $subject= "cyrillic subject";
my $message= "cyrillic message";


my %mail = (
        To      => '[email protected]',
        Subject => "$subject",
        From    => '[email protected]',
        Message => "$message",
       );

sendmail(%mail) or die $Mail::Sendmail::error;

print "OK. Log says:\n", $Mail::Sendmail::log;

Solution

  • Problem solved without use utf8 and without use Encode.

    I've added 'Content-type' => 'text/html; charset="utf-8"' header and everything become fine!