We can assign the custom email template for mailing in magento. For this we have template tag in xml file. Here I am assigning new email template for requesting quote in contact us form. Below are the steps you can perform to assign custom email template -
1) Write following lines in config.xml of your module -
<template>
<email>
<quote_mail module="module_name">
<label>Quote Requested</label>
<file>quote_request.html</file>
<type>html</type>
</quote_mail>
</email>
</template>
2) Now create a html file in your language locale folder e.g. in app/locale/en_US/template/email/ folder create quote_request.html file with the variables you want to use in html file to display info.
3) Now create the function in the controller to send email and assign a value to the variables to pass in html file.
public function sendCustomMail()
{
/** content of the mail **/
$mail = new Zend_Mail();
$mailFrom = "sender@email.com";
$receiverName = 'donotreply';
$mailTo = 'example@example.com';
$subjectName = 'Subject of mail';
/** email variables **/
$emailTemplateVariables = array();
$emailTemplateVariables['firstName'] = "firstname";
$emailTemplateVariables['lastName'] = "lastname";
$emailTemplateVariables['emailAddress'] = "request@email.com";
$emailTemplateVariables['telephone'] = "number of mobile of receiver";
/** load custom email template which we have created to send mail **/
$emailTemplate = Mage::getModel('core/email_template')->loadDefault('quote_mail'); // where quote_mail is our template tag which decide which file to be loaded for the mail //
$emailTemplate->setSenderName(Mage::helper('core')->escapeHtml($emailTemplateVariables['firstName'])." ".Mage::helper('core')->escapeHtml($emailTemplateVariables['lastName']));
$emailTemplate->setSenderEmail($emailTemplateVariables['emailAddress']);
$emailTemplate->setType('html');
$emailTemplate->setTemplateSubject($subjectName);
$emailTemplate->send($mailTo, $receiverName, $emailTemplateVariables);
Mage::getSingleton('customer/session')->addSuccess($this->__('Mail has been sent successfully.'));
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl());
/** End **/
}
4) Now to use these variables in a html file you have to call using {{var firstName}} , this will show the value of 'firstName' variable. Similary you can use rest of the variables as per requirement in a template file.
By this you can call create and call any custom html file for mailing if you don't want to use the default mailing files.
0 Comment(s)