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.

David Manners
27.3k9 gold badges78 silver badges220 bronze badges
asked Feb 19, 2015 at 8:07
4
  • Try to configure the store (in your localhost) in development mode. And try to check if there are any error logs. Commented Feb 19, 2015 at 8:15
  • @MagePsycho no, I did not get any error log. I checked it already Commented Feb 19, 2015 at 8:17
  • Try to put that email template to base/default folder and check. Commented Feb 19, 2015 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. Commented Feb 19, 2015 at 9:12

2 Answers 2

5

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

answered Feb 19, 2015 at 8:18
1
  • I have already tried it. But it has not worked.. Commented Feb 19, 2015 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 protected]', 'name', $emailTemplateVariables);
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

Hope it helps.

answered Jul 8, 2015 at 17:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.