Search code examples
magentomagento-1.5email-templates

How to use the Email template in Magento


I develop my store in magento community edition 1.5.0.1. I need a Email template that content will be editable by admin. I create a email template through admin "Transactional Emails". Now I need to access and use that email from my custom module. How do I get it?, you have any idea let me know.


Solution

  • This should do it.

    public function sendTransactionalEmail() {
    
            // Transactional Email Template's ID
            $templateId = 1;
    
            // Set sender information
            $senderName = Mage::getStoreConfig('trans_email/ident_support/name');
            $senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
            $sender = array('name' => $senderName,
                        'email' => $senderEmail);
    
            // Set recepient information
            $recepientEmail = '[email protected]';
            $recepientName = 'John Doe';        
    
            // Get Store ID
            $storeId = Mage::app()->getStore()->getId();
    
            // Set variables that can be used in email template
            $vars = array('customerName' => '[email protected]',
                      'customerEmail' => 'Mr. Nil Cust');
    
            $translate  = Mage::getSingleton('core/translate');
    
            // Send Transactional Email
            Mage::getModel('core/email_template')
                ->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
    
            $translate->setTranslateInline(true);
    }