2016-04-12 10 views
0

私はmagento shopでカスタムメールを送信しています。トランザクションテンプレートを使用していますが、これは問題ありません。問題は、magentoがMage/Page/etc/config.xmlのdefault_encoding = 'utf-8'と同じカスタム電子メールのiso-8859-1エンコーディングを使用していることです。Magentoのメールモデルのエンコーディングは、残念ながらデフォルトはiso-8859-1です。

直接エンコーディングを設定する機能ですが、エンコーディングを見つけられませんでした。誰かがこの問題に遭遇し、それを解決しましたか? 私はそれをすばやく修正する必要があります。私は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("[email protected]") 
     ->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

OK、解決策を見つけました...クイックフィックスはコアを編集するか、Core/Model/Email.php send関数を拡張します。そこでは、$ mail = new Zend_Mail();を変更します。 $ mail = new Zend_Mail( 'utf-8');エンコードをutf-8に設定するか、ストア設定からデフォルトのエンコードを取得します –

答えて

0

Magentoのコアを拡張するための適切な方法:アプリ/コードで

/ローカル/ YOURTHEME/MODULE /モデル/ 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; 
    } 
} 

とconfig.xml in app/code/local/YOURTHEME/MODULE/etc/config.xml:

<global> 
    <models> 
     <core> 
      <rewrite> 
       <email>YOURTHEME_MODULE_Model_Email</email> 
      </rewrite> 
     </core> 
    </models> 
</global> 
関連する問題