Magento问题与电子邮件charset

时间:2013-06-25 22:09:38

标签: magento email magento-1.7

我有一点问题。我正在使用我的自定义模块发送邮件这段代码:

$content = 'Wiadomość testowa ąśźć';

$mail = Mage::getModel('core/email');
        $mail->setToName($name);
        $mail->setToEmail($email);
        $mail->setBody($content);
        $mail->setSubject($subject);
        $mail->setFromEmail('test@test.com');
        $mail->setFromName("Test");
        $mail->setType('html');

        try {
            $mail->send();
            Mage::getSingleton('customer/session')->setData('success',Mage::helper('adminhtml')->__('Your request has been sent'));
        }
        catch (Exception $e) {
            Mage::getSingleton('customer/session')->setData('error',Mage::helper('adminhtml')->__('Unable to send email.'));
        }

如何在使用magento邮件功能发送电子邮件之前设置utf-8字符集。 ? 我在电子邮件正文中收到没有utf-8字符集的电子邮件。

解决 我在helper中创建了sendZendMail函数。 我使用了这个函数,而不是Magento core/email

public function sendZendMail($name,$email,$subject,$content){
    $mail = new Zend_Mail('UTF-8');
    $mail->setBodyHtml($content);
    $mail->setFrom('your@frommail.com');
    $mail->addTo($email, 'No reply');
    $mail->setSubject($subject);
    try {
        $mail->send();
        Mage::getSingleton('core/session')->addSuccess('Mail was sucessfully send.');
    }
    catch(Exception $ex) {
        Mage::getSingleton('core/session')->addError('Unable to send email.');
    }       
}

1 个答案:

答案 0 :(得分:3)

克里斯托夫,我之前和葡萄牙语有同样的问题,葡萄牙语也有特殊字符。我已经通过使用函数htmlentities()对重音词进行了整理。 Zend Mail对象有点迟钝。我希望它有所帮助。

相关问题