Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 404
R R Avatar asked Nov 30 '13 06:11

R R


2 Answers

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:

//Setting the Language as Japan
mb_language("ja");

//Converting the string into Japan Encoding
$subject = mb_convert_encoding($subject, "ISO-2022-JP","AUTO");

//Now convert the string to MIME Header type
$subject = mb_encode_mimeheader($subject);

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.

like image 58
Vineet1982 Avatar answered Sep 29 '22 17:09

Vineet1982


Are you test to change the charset with .htaccess ?

AddDefaultCharset   UTF-8
like image 43
ColoO Avatar answered Sep 29 '22 18:09

ColoO