php - Joomla UTF-8 encoding fails on opening the mail
I have a strange issue with encoding, described as follows:
the ù is now shown as ù in the email subject. The email is sent through php mail function.
When viewing the e-mail in the mailbox, it is shown correctly. However, when anybody opens the e-mail, the ù is suddenly changed to ù.
Uw contact met Meeùs
should be
Uw contact met Meeùs
i have already used the encoding.
$emailsubject
contains the above mentioned email subject.
$subject=$emailsubject;
$subject=$emailsubject;
$email_message=new email_message_class;
$email_message->SetEncodedEmailHeader("To",$to_address,$to_name);
$email_message->SetEncodedEmailHeader("From",$from_address,$from_name);
$email_message->SetEncodedEmailHeader("Reply-To",$reply_address,$reply_name);
$email_message->SetHeader("Sender",$from_address);
$email_message->SetEncodedHeader("Subject",$subject,"UTF-8");
In localhost it is working properly, but in the webserver it is not working properly. In webserver also encoding is set to utf-8 by default.
What i am doing wrong? Thanks in advance.
Answer
Solution:
Your code is correct absolutely there is no error in it but its other things failing encoding. As I need message source headers and message to tell you exactly what is happening? I have further no information about are you sending the email as plain text or HTML. But there are generally two issue which are:
Missing Mime-Version
Reason for showing the character wrongly is developers forget to describe the message as MIME Version. if the message is missing the "Mime-Version" header that Internet mail standards require, Webmail will ignore the "charset" header completely, garbling the message unless it's already in the UTF-8 character set.
Showing Subject with Special Characters
As you want to show the subject with utf-8 encoding then you must encode the subject as:
If the above mentioned things doesn't resolve the problem then request you post the RAW Headers of the Email as it will help in better way to resolve issue.
Answer
Solution:
Are you test to change the charset with .htaccess ?
Answer
Solution:
Since you indicate in the comments you are using Joomla 1.5, it seems there is an issue with the
phpmailer()
library in that version that forces the character set of the mailer—on the message—to send things out using the character set setting ofiso-8559-1
. To fix this open up the corephpmailer()
libary here:Around line 50 there is a setting called
$CharSet
. Change that toutf-8
if it’s not set to that already:You might also want to do search of your Joomla 1.5 codebase for
iso-8559-1
to see if a component or library is forcingiso-8559-1
encoding somewhere in the chain of code.And another setting I would recommend checking is
$Encoding
around line 63. The default setting seems to be8bit
, but I have had to adjust that in the past to eitherquoted-printable
orbase64
to solve some mailing issues on specific setups I was working on.Answer
Solution:
I suggest you to use joomla mailer class, the could would look like this:
It's utf8 by default, and i don't see any reasons for not to use it, if you're using Joomla.