PHP Mail, setlocale, and accented characters
<p>I have a problem with sending mails that preserve accented characters. By reading some pages and the answers to previously asked questions I was able to find a solution that works (partially).</p>

<p>I have no problem with the following code, that works correctly (i.e. I see accented characters in the eMail client I use). It uses the PEAR php library. However, this code is only good for English, as I will explain later on.</p>

<pre><code>...
$headers['From'] = "info@website.it";
$headers['Subject'] = 'Request';
$headers['Reply-To'] = $sanitized_email; 
$headers["Content-Type"] = 'text/html; charset=UTF-8';
$headers["Content-Transfer-Encoding"]= "8bit";

$host= _CMS_MAIL_SERVER;
$username = "info@website.it";
$password = "pass";

$crlf = "\n";
$mime = new Mail_mime(array('eol' =&gt; $crlf));

$html_body = ...;
// read $html_body from file
// substitute some %tags% in $html_body
$mime-&gt;setHTMLBody($html_body); 

$mimeparams['text_encoding']="8bit"; 
$mimeparams['text_charset']="UTF-8"; 
$mimeparams['html_charset']="UTF-8"; 
$mimeparams['head_charset']="UTF-8"; 

$mimebody = $mime-&gt;get($mimeparams);
$hdrs = $mime-&gt;headers($headers);

$smtp = Mail::factory('smtp', array ('host' =&gt; $host, 'auth' =&gt; true, 'username' =&gt;     $username, 'password' =&gt; $password));

$mail_res = $smtp-&gt;send($recipients, $hdrs, $mimebody);
...
</code></pre>

<p>In the $html_body I have some tags that I need to substitute with time and date values, as returned by date or strftime(..). Since the default locale is English, in order to have Italian dates and times I need to set the locale before calling strftime(...).</p>

<p>If I add this line:</p>

<pre><code>setlocale(LC_TIME, "it_IT");
</code></pre>

<p>accented characters are not displayed correctly by the mail client. More in details: accented characters returned by strftime are displayed correctly (e.g. lunedì), while accented characters submitted via the form field are not.</p>

<p>I made some research to understand how I can correct that error, but I did not find any solution. Furthermore, it is not clear to me what the relationship between setlocale on LC_TIME and accented characters is. </p>

<p>Is there anyone who can help me?</p>
