in reply to Character encoding in emails

I assume you are sending to each method from separate webpages. Have you checked that both of the forms are set to accept utf8 encoding, something like this?
<form name="myform" id="myform" accept-charset="utf-8" method="post" a +ction="myperlscript.pl">
Assuming the forms, the HTML pages themselves, etc. all have identical configuration with respect to their meta tags' encoding, etc., you might then look at the difference between where the information is stored in the database, perhaps with the utf8mb4 encoding, and where the text gets passed for processing to be immediately sent. What encodings are involved in the hand-off?

One possible "gotcha": Watch out for setting the print handle to "hot", i.e. $| = 1;. This can sometimes have unexpected results. If in doubt, avoid using it.

But I would expect that the issue lies closer to what Perl itself is doing with your data. If it sends through the database, it is not outputting the data via STDOUT. The encodings between what goes to the DB versus what goes to STDOUT can, and often do, differ--unless you have explicitly set them the same. As you say the database route is working, it may be already setup correctly (or else it is setup so that the error gets corrected upon retrieval from the DB). Note that use utf8; does NOT mean your Perl script will be set for working with utf8 in its input/output; it only means it will be able to save the script itself in utf8 format and be aware of its own encoding, not that of external sources. For other sources, you may wish to use one of the following:

use feature 'unicode_strings'; use open ':encoding(utf8)'; #DEAL WITH ALL FILES IN A UTF8 +WAY binmode STDIN, ':utf8'; #MORE LIBERAL binmode STDOUT, ':utf8'; #MORE LIBERAL # - OR - binmode STDIN, ":encoding(UTF-8)"; #MORE SECURE, ESP. ON READ binmode STDOUT, ":encoding(UTF-8)"; #MORE SECURE, ESP. ON READ

Blessings,

~Polyglot~