3

I am trying to send coupon code with email on new account registration. For that I created email template system > transactional emails.

Here in this email template I have included coupon.phtml file which is located at app/design/frontend/theme/default/template/email/coupon.phtml using below code.

{{block type="core/template" name="email_coupon" template="email/coupon.phtml"}}

But this is not working. I am not getting any html which I have added in coupon.html. Please guide where I have mistaken.

  • Try to configure the store (in your localhost) in development mode. And try to check if there are any error logs. – MagePsycho Feb 19 '15 at 8:15
  • @MagePsycho no, I did not get any error log. I checked it already – mike smith Feb 19 '15 at 8:17
  • Try to put that email template to base/default folder and check. – MagePsycho Feb 19 '15 at 8:23
  • @MagePsycho yes, That I had worked when I put file in base/default folder. Now I am wondering why it has not worked with my theme. – mike smith Feb 19 '15 at 9:12
4

For this case you need to create a handler and this handler will render the you phtml( at local.xml at app/design/frontend/YOUR_PAackage/YOUR_template/layout) on html template

<?xml version="1.0"?>
<layout version="0.1.0">
    <amit_customer_addhan>
        <block type="core/template" name="email_coupon" template="email/coupon.phtml" />
    </amit_customer_addhan>
</layout>

then on email html template call handler

   {{layout handle="amit_customer_addhan" }}

OR: Without call of handler:

call a block file without layout handler and ans parameter for

 {{block type='core/template' area='frontend' template='email/coupon.phtml' }}

\ see more at Display line in transactional e-mail if payment method is

  • I have already tried it. But it has not worked.. – mike smith Feb 19 '15 at 8:21
0

The problem here is not how the template is called (@Amit Bera gave the correct way to do that part), but in what store it is called from. If your code executes from the Admin, it will pick up the base/default instead of your template.

So here is how you need to do it:

$appEmulation = Mage::getSingleton('core/app_emulation');
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
$emailTemplate  = Mage::getModel('core/email_template')->loadDefault('your_template');

$emailTemplate
    ->setSenderName(...)
    ->setSenderEmail(...)
    ->setTemplateSubject(...)
    ->setTemplateType('html');

$emailTemplate->send('email@example.com', 'name', $emailTemplateVariables);
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

Hope it helps.

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.