Magento – Getting HTML of transactional emails

emailhtmlmagento-1.9

I would like to know if it's possible to get code html of transactional emails before send email to user with template variables etc…

I override _sendEmailTemplate and I try to get HTML code in this way:

protected function _sendEmailTemplate($template, $sender, $templateParams = array(), $storeId = null) {
        /** @var $mailer Mage_Core_Model_Email_Template_Mailer */
        $mailer = Mage::getModel('core/email_template_mailer');
        $emailInfo = Mage::getModel('core/email_info');
        $emailInfo->addTo($this->getEmail(), $this->getName());
        $mailer->addEmailInfo($emailInfo);

        // Set all required params and send emails
        $mailer->setSender(Mage::getStoreConfig($sender, $storeId));
        $mailer->setStoreId($storeId);
        $mailer->setTemplateId(Mage::getStoreConfig($template, $storeId));
        $mailer->setTemplateParams($templateParams);
        $emailTemplate = Mage::getModel('core/email_template')->loadByCode($template); // I try to get template


        $processedTemplate = $emailTemplate->getProcessedTemplate($templateParams); //set template variables and get html code
        print_R($processedTemplate);
        exit;
        $mailer->send();
        return $this;
    }

Comments in code.

It doesn't work. Any ideas will be appreciated

Best Answer

It depends on what you want to do with the HTML code, but what I used to do to debug emails is log the email HTML code into a file.

Instead of using print_r, you can do:

Mage::log($processedTemplate, null, sprintf("email_%s.html", date("Ymd-his")));
Related Topic