Email Magento电子邮件型号编码默认为iso-8859-1
我正在magento商店发送一封自定义电子邮件。它使用事务模板,这很好。问题是,magento对该自定义电子邮件使用iso-8859-1编码,而不使用Mage/Page/etc/config.xml中的默认_编码='utf-8' 我试图查找一个函数来直接设置编码,但没有找到。有人遇到这个问题并解决了吗? 我需要它来快速修复。我知道我应该更好地使用magento的事务性邮件系统,但我们不能对该系统进行重大更改,因为它刚刚上线,我们还没有运行的开发环境 我的代码:Email Magento电子邮件型号编码默认为iso-8859-1,email,magento,encoding,utf-8,iso-8859-1,Email,Magento,Encoding,Utf 8,Iso 8859 1,我正在magento商店发送一封自定义电子邮件。它使用事务模板,这很好。问题是,magento对该自定义电子邮件使用iso-8859-1编码,而不使用Mage/Page/etc/config.xml中的默认_编码='utf-8' 我试图查找一个函数来直接设置编码,但没有找到。有人遇到这个问题并解决了吗? 我需要它来快速修复。我知道我应该更好地使用magento的事务性邮件系统,但我们不能对该系统进行重大更改,因为它刚刚上线,我们还没有运行的开发环境 我的代码: public function
public function customerSaveBefore($observer) {
$customer = $observer->getCustomer();
//Array of customer data
$customerData = $customer->getData();
//email address from System > Configuration > Contacts
$contactEmail = Mage::getStoreConfig('contacts/email/recipient_email');
//customer is new, otherwise it's an edit
if (!$customer->getOrigData()) {
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$addressData = $session->getCustomerAddress(); //get customers address from session variable
$emailTemplate = Mage::getModel("core/email_template")
->loadDefault("customer_notification");
$emailTemplateVariables = array();
$emailTemplateVariables["customer"] = $customer;
$emailTemplateVariables["plz"] = $addressData['postcode'];
$emailTemplateVariables["city"] = $addressData['city'];
$emailTemplateVariables["company"] = $addressData['company'];
$emailTemplateVariables["street"] = $addressData['street'][0];
$emailTemplateVariables["phone"] = $addressData['telephone'];
$emailTemplateVariables["erpid"] = $session->getCustomerUserId();
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
$mail = Mage::getModel("core/email")
->setToEmail("steinmille@gmail.com")
->setBody($processedTemplate)
->setFromEmail($sender)
->setFromName("EMAIL")
->setSubject("Subject")
->setType("html");
try{
$mail->send();
}
catch(Exception $error)
{
Mage::getSingleton("core/session")->addError($error->getMessage());
return false;
}
$mail->setToEmail($recipient)
->setFromEmail($recipient);
try{
$session->setCustomerAddress([]); //clear customers address in session variable
}
return true;
}
扩展magento core的正确方法: 在app/code/local/YOURTHEME/MODULE/Model/Email.php中
class YOURTHEME_MODULE_Model_Email extends Mage_Core_Model_Email{
public function send()
{
if (Mage::getStoreConfigFlag('system/smtp/disable')) {
return $this;
}
$mail = new Zend_Mail('utf-8');
if (strtolower($this->getType()) == 'html') {
$mail->setBodyHtml($this->getBody());
}
else {
$mail->setBodyText($this->getBody());
}
$mail->setFrom($this->getFromEmail(), $this->getFromName())
->addTo($this->getToEmail(), $this->getToName())
->setSubject($this->getSubject());
$mail->send();
return $this;
}
}
app/code/local/YOURTHEME/MODULE/etc/config.xml中的config.xml:
<global>
<models>
<core>
<rewrite>
<email>YOURTHEME_MODULE_Model_Email</email>
</rewrite>
</core>
</models>
</global>
YOURTHEME\u模块\u模型\u电子邮件
ok,找到了解决方案。。。Quickfix用于编辑core或扩展core/Model/Email.php发送函数。在这里,change$mail=new Zend_mail();to$mail=新Zend_邮件('utf-8');将编码设置为utf-8或从存储配置中获取默认编码