Dear fellow monks,
I have an issue with MIME::Lite::TT::Html in that it does not properly handle umlauts (UTF-8 in general).
This is my sample code:
#!/usr/bin/env perl
use strict;
use warnings;
use MIME::Lite::TT::HTML;
use Encode;
my %params;
$params{umlaut} = 'fööbär';
Encode::_utf8_on($params{umlaut});
my %options= (
INCLUDE_PATH => '.',
ENCODING => 'UTF-8',
);
my $msg = MIME::Lite::TT::HTML->new(
From => 'admin@example.com',
To => 'frank@example.com',
Subject => 'Your recent purchase',
Template => {
text => 'revsys.txt.tt',
html => 'revsys.html.tt',
},
TmplOptions => \%options,
TmplParams => \%params,
);
binmode STDOUT, ':utf8';
print "Should be: ", $params{umlaut},$/;
print '-' x 79,$/;
print $msg->as_string;
And these are the templates:
revsys.txt.tt:
text: [% umlaut %]
revsys.html.tt:
<h1>[% umlaut %]</h1>
The output is:
Should be: fööbär
----------------------------------------------------------------------
+---------
Content-Transfer-Encoding: binary
Content-Type: multipart/alternative; boundary="_----------=_1580806618
+90"
MIME-Version: 1.0
X-Mailer: MIME::Lite 3.031 (F2.85; T2.17; A2.21; B3.15; Q3.13)
Subject: =?US-ASCII?B?WW91ciByZWNlbnQgcHVyY2hhc2U=?=
Date: Tue, 4 Feb 2020 08:56:58 +0000
To: frank@example.com
From: admin@example.com
This is a multi-part message in MIME format.
--_----------=_158080661890
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
text: fbr
--_----------=_158080661890
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
Content-Type: text/html; charset=us-ascii
<h1>fbr</h1>
--_----------=_158080661890--
As you can see: The Template output is just "fbr" and should be "fööbär".
Any advice? Did I do something wrong? Are there alternatives I should consider which can handle UTF-8?
s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.