Joomla UTF-8 encoding fails on opening the mail
Asked Answered
E

4

8

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.

Empathize answered 30/11, 2013 at 6:4 Comment(11)
@JakeGould it doesnot encode at all after excluding,it gives strange letters.Empathize
i am using joomla @JakeGouldEmpathize
@JakeGould do u have any clue whats going wrong?Empathize
1. What version of Joomla are you using because this isn't a class from 1.5 - 2.5 or the 3.x series?Explant
@cppl i am using version 1.5Empathize
I would have to agree with @JakeGould as this seems like double encoding, the same thing happened to me a while ago - check the message source of the email(which shows you a raw log of the email) , and put it in a pastebin (hide any email addresses) : example using Gmail - email.about.com/od/gmailtips/ss/wt_view_source_2.htmEffortless
@Scorpion thanks for the reply but even after removing the 2nd encoding the issue persists.Empathize
What piece of software provides the e-mail reading, i.e. the mailbox and the message list and displaying the email? Is it a mail component in Joomla, or is it a webmail service like gmail, or is it something different? Your question doesn't say this clearly. You seem to imply that what Joomla is doing is sending the email.Femur
@JimDeLaHunt it is a webmail service like gmailEmpathize
OK, what is the name of the webmail service? Have you done any tests to see if this webmail service is working correctly, or is the problem? For instance, have you sent an email with the subject line which causes problems from a different sender, like Gmail, to this webmail service? What is the result of that test?Femur
i tested it in gmail and yahoo but still the subject showing wrong encoding.Empathize
A
3

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.

Amide answered 8/12, 2013 at 17:58 Comment(1)
i will test it and will let you know,i am accepting it as so far this seems the good answer to my question.Empathize
P
1

Are you test to change the charset with .htaccess ?

AddDefaultCharset   UTF-8
Pelpel answered 2/12, 2013 at 13:49 Comment(4)
Have you test my answer Rishab Raj ?Pelpel
hum... can you do one test : $subject = utf8_decode("Uw contact met Meeùs");Pelpel
the content of your mail is in your sql ? have you analyze the header of your mail in gmail ?Pelpel
ya the contents are getting fetched from sql and i have analized my mail in gmail and other alsoEmpathize
S
1

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 of iso-8559-1. To fix this open up the core phpmailer() libary here:

[path to your Joomla install]/libraries/phpmailer/phpmailer.php

Around line 50 there is a setting called $CharSet. Change that to utf-8 if it’s not set to that already:

  /**
   * Sets the CharSet of the message.
   * @var string
   */
  var $CharSet           = 'utf-8';

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 forcing iso-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 be 8bit, but I have had to adjust that in the past to either quoted-printable or base64 to solve some mailing issues on specific setups I was working on.

  /**
   * Sets the Encoding of the message. Options for this are "8bit",
   * "7bit", "binary", "base64", and "quoted-printable".
   * @var string
   */
  var $Encoding          = '8bit';
Samira answered 2/12, 2013 at 15:27 Comment(1)
i will definately try it tommorow and will keep you updated,thanks for your timeEmpathize
L
1

I suggest you to use joomla mailer class, the could would look like this:

$mailer = JFactory::getMailer();
$mailer->setSender(array($from_address,$from_name));
$mailer->addRecipient($to_address, $to_name);
$mailer->setSubject($subject);
$mailer->setBody("BODY MESSAGE STRING");
$mailer->Send();

It's utf8 by default, and i don't see any reasons for not to use it, if you're using Joomla.

Licence answered 4/12, 2013 at 5:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.