Magento E-commerce Platform Q/ A

How to Create E-mail Templates in Magento

To create a custom e-mai template in Magento, you need to specify it in the config.xml file of the module.  Example: Place this code between the tags

<global>

                                   <template>

                                               <email>

                                                           <ikantam_custom_email module="ikantam">

                                                           <label>Ikantam email</label>

                                                           <file>ikantam_email.html</file>

                                                                        <type>html</type>

                                                           </ ikantam_custom_email >

                                               </email>

                                   </template>

</global>

The next step is to create php code to send e-mails. Example:

$emailTemplate = Mage::getModel('core/email_template')

               ->loadDefault('ikantam_custom_email');// uploading template

$emailTemplateVariables = array(); //passed to the template variables array

$emailTemplateVariables['index'] =''value''; //creating variable

               

            $processedTemplate = $emailTemplate-getProcessedTemplate($emailTemplateVariables);

        // parcing

$emailTemplate->setSenderName('Name from sent email');// sender name

$emailTemplate->setSenderEmail('email address');// sender email address

$emailTemplate->setTemplateSubject('description');//title text

$emailTemplate->send(''email address'',''description'', $emailTemplateVariables);// recipient email address, could be name of the recipient or any other information, variables array.

     

And finally you need to create an html template of the e-mail with the name (for the example that we use): ikantam_email.html and place it into locale -> choose language group (en_US) -> template -> email. As far as you've indicated html, the template could be created using available html tags. In order to receive and display the variables use this code:

 

{{ var name variable }}

 in the described example it is: index. Example:

    <body>

         ...........

           <p>

                   Your information {{var index }}.

                      

            </p>

         ...........

         </body>