2

I need to unicode "images" (icons) in the subject, for example, to display this image [☮], I can use the following code with the core/email model.

$subject='☮';
$mailModel=Mage::getModel('core/email');
$mailModel->setSubject('=?utf-8?B?'.base64_encode($subject).'?=')

However the following code (for the core/email_template model) is not working,

$_mailModel = Mage::getModel('core/email_template');
$_mailModel->setTemplateSubject('=?utf-8?B?'.base64_encode($subject).'?=');

it returns =?utf-8?B?SG93IHdhcyB5b3VyIG9yZGVyPyBKdXN0IGNoZWNraW5nIGluLi4u4pmlIFBMVVIg4piuIA==?=

How to display the image using the second core/email_template model.

1 Answer 1

1
+50

I think you should just add the template subject without encoding it:

$_mailModel = Mage::getModel('core/email_template');
$_mailModel->setTemplateSubject('How was your order? Just checking in...♥ PLUR ☮');

Here is why I think it should work.
The e-mail is sent from Mage_Core_Model_Email_Template::send(). This method uses an instance of Zend_Mail. See this line: $mail = $this->getMail();. The method getMail() looks like this:

public function getMail()
{
    if (is_null($this->_mail)) {
        $this->_mail = new Zend_Mail('utf-8');
    }
    return $this->_mail;
}

And later on the subject is set on the $mail object:

$mail->setSubject('=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?='); 

and this encodes it so there is no need for you to encode the value you set.
If the subject is a simple text, then getProcessedTemplateSubject will return it as it is. That method is used to parse the short codes in the subject ({{var ...}}).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.