use strict;
use warnings;
use Encode;
use Encode::Guess;
use MIME::Words qw(:all);
my $mime = MIME::Lite->new( {
From => mime_escape( $p{from} ),
To => mime_escape( $p{to} ),
Subject => mime_escape( $p{subject} ),
Data => $p{body},
} );
$mime->attr('content-type.charset' => 'UTF8';);
$mime->send;
sub mime_escape {
my $data = shift || '';
my $utf8 = decode("Guess", $data);
return encode_mimewords( $utf8 );
}