I have created a Transactional Emails template in magento admin to send multiple coupon codes dynamically for this I have created a template file says email/custom.phtml and it is included in email template.

It is included in email template successfully but I am trying to add {{var code12}}, {{ var code13 }} etc. with multiple time but it is not working.

If I add these in direct email template in magento admin then it is working as I want but I want to create {{var}} also dynamically.

I am using below code for sending email :

$senderName = 'custom';
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');

$emailTemplate = Mage::getModel('core/email_template')->loadByCode('Custom Template');;
$emailTemplateVariables = array();
$emailTemplateVariables['name'] = 'name';
$emailTemplateVariables['code12'] = 'AB56FFD';
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
$mail = Mage::getModel('core/email')
        ->setSubject('Coupon code')

My custom.phtml code is here :

##My shopping cart rule are product specific
$allProducts = array(10,20,30);
foreach($allProducts as $product_id)
    $product = Mage::getModel('catalog/product')->load($product_id);
    echo $product->getName();
    echo Mage::getModel('core/variable')->loadByCode('code12')->getValue('text');  // it is not working
    {{var code12}}  // it is not working

And Transactional Emails template code is here :

{{block type="core/template"  name="email_custom" template="email/custom.phtml" }}

How to add custom variables in phtml file?

  • sorry don't understand you want to add phml file in email template or pass multiple variable to email template – Qaisar Satti Oct 19 '16 at 10:19
  • Yes I want to send multiple coupon code to one customer and for this calculation I have created a custom.phtml file which is included in email template. In event observer I generated code dynamically and saved to shopping cart rule. and at the time of email sending wants to send those code. – Vinaya Maheshwari Oct 19 '16 at 10:25
  • Hello @NikunjPatel, Can you explain link provided by you? – Vinaya Maheshwari Oct 19 '16 at 10:27
  • kindly add the phtml and email template code too. – Qaisar Satti Oct 19 '16 at 10:33

pass a array

$emailTemplateVariables['code'] = array('code12'=>'AB56FFD','code13'=>'AB5fd6FFD','code14'=>'AB56dfFFD') ;

you have to pass variable to phtml file

{{block type="core/template"  name="email_custom" template="email/custom.phtml" code=$code}}

in phtml file

$code= $this->getCode();
echo $code['code12'];
  • It will work with multiple variable? like {{block type="core/template" name="email_custom" template="email/custom.phtml" code12=$code12 code10=$code10}} – Vinaya Maheshwari Oct 19 '16 at 10:46
  • yes it will work but it is better to pass array. – Qaisar Satti Oct 19 '16 at 10:47
  • How to pass array? – Vinaya Maheshwari Oct 19 '16 at 10:51
  • @VinayaMaheshwari updated the code – Qaisar Satti Oct 19 '16 at 10:53
  • Hello @QaisarSatti, When I am using $code= $this->code() then an empty email received? – Vinaya Maheshwari Oct 19 '16 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.