我在magento商店发送自定义电子邮件。它使用的是事务模板,很好。问题是,magento对该自定义电子邮件使用iso-8859-1编码,默认来自Mage / Page / etc / config.xml的default_encoding ='utf-8'
我试图查找直接设置编码的函数,但未能找到。有人遇到过这个问题并解决了吗? 我需要它来快速修复。我知道我应该更好地使用magento的事务性邮件系统,但我们不能对系统进行重大更改,因为它刚刚上线,我们还没有正在运行的开发环境。
我的代码:
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;
}
答案 0 :(得分:0)
扩展magento核心的正确方法:
在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中的和config.xml / code / local / YOURTHEME / MODULE / etc / config.xml:
<global>
<models>
<core>
<rewrite>
<email>YOURTHEME_MODULE_Model_Email</email>
</rewrite>
</core>
</models>
</global>