php - Joomla UTF-8 encoding fails on opening the mail

382

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.

809

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:

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

848

Answer

Solution:

Are you test to change the charset with .htaccess ?

AddDefaultCharset   UTF-8
760

Answer

Solution:

Since you indicate in the comments you are using Joomla 1.5, it seems there is an issue with thephpmailer() 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:

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

Around line 50 there is a setting called$CharSet. Change that toutf-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 foriso-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.

  /**
   * Sets the Encoding of the message. Options for this are "8bit",
   * "7bit", "binary", "base64", and "quoted-printable".
   * @var string
   */
  var $Encoding          = '8bit';
116

Answer

Solution:

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.

People are also looking for solutions to the problem: php - How to log in social networking sites like facebook, twitter and google+ to my websites in Zend Framework 1.12?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.