Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:43:38+00:00 2026-06-03T05:43:38+00:00

I have a problem with sending mails that preserve accented characters. By reading some

  • 0

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).

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.

...
$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' => $crlf));

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

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

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

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

$mail_res = $smtp->send($recipients, $hdrs, $mimebody);
...

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(…).

If I add this line:

setlocale(LC_TIME, "it_IT");

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.

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.

Is there anyone who can help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:43:40+00:00Added an answer on June 3, 2026 at 5:43 am

    I solved the problem.

    setlocale(…) switches character encoding even if it does not need to.

    In this case setlocale(LC_TIME, “it_IT”) was switching from UTF-8 to ISO-8859-1 and the receiving page was using UTF-8.

    When using UTF-8 the correct way to set locale is:
    setlocale(LC_TIME, “it_IT.UTF-8”).

    It was obvious the problem was related to character encodings, but setlocale should not change locale if the encoding in use is ok for the language (or should it?).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problems sending mails through SMTP using Spring's MailSender interface and the
greetings all i have a problem that when sending an email from the server
I have a problem sending plain text emails using PHPMailer. I have text that
I have a problem sending POST request with VB6. The code below works properly
Hi I have a problem in sending data from php to pdf. I think
I have a problem when I want to sending data using byte format in
I have a problem when trying to send a POST request. The sending method
I have a little problem, I'm making project and I'm sending data from client
I have some problems sending an id though jquery. I have a form select
I am sending soap messages that contains arrays. I have problems with arrays in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.