emailencodingspecial-characterssubjectaol

Aol mail subject special characters not showing correctly


For sending wishes for an event like Administrative Professionals Day® I try to send mail vai all the mail providers to my users and the receivers are getting email subject correctly except the AOL mail providers the special characters(the register sign) which we are seeing here is not getting rendered well. I am using perl. Part of the codes are as follows.

my $email_subject = _decode_html_entities($q->param('email_subject'));
my $email_msg = MIME::Lite->new(
            From     => '$frm',
            To       => $email_to,
            Subject  => '=?utf-8?B?'.encode_base64($email_subject).'?=',
            Type     => 'text/plain',
            Encoding => 'base64',
            Data     => $email_body
        );
        $email_msg->attr("content-type.charset"   => 'UTF8');
        $email_msg->add( 'X-Card-Nos' => $uc );
        $email_msg->add( 'X-Type'     => 'Test_YearAfter_Reminder' );
        $email_msg->add( 'Errors-To'  => $error_mail_rec );

sub _decode_html_entities {
    my $str = shift;
    $str =~ s/%([a-f0-9]{2})/chr(hex($1))/egi;
    return encode_utf8($str);
}

Other email providers showing mail subject as

Administrative Professionals Day® ecards

whereas aol mail subject showing subject line as

=?utf-8?B?QWRtaW5pc3RyYXRpdmUgUHJvZmVzc2lvbmFscyBEYXnCriBlY2FyZHM= ?=


Solution

  • Make the following changes:

    $email_msg->attr("content-type.charset"   => 'UTF-8');
    

    No need for default EOL "\n":

    Subject  => '=?utf-8?B?'.encode_base64($email_subject,'').'?=',
    

    Also, no need to encode to utf8 if you are using 'use utf8' in your script.