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– MagePsycho2015年02月19日 08:15:20 +00:00Commented Feb 19, 2015 at 8:15
-
@MagePsycho no, I did not get any error log. I checked it alreadymike smith– mike smith2015年02月19日 08:17:35 +00:00Commented Feb 19, 2015 at 8:17
-
Try to put that email template to base/default folder and check.MagePsycho– MagePsycho2015年02月19日 08:23:15 +00:00Commented 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.mike smith– mike smith2015年02月19日 09:12:44 +00:00Commented Feb 19, 2015 at 9:12
2 Answers 2
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– mike smith2015年02月19日 08:21:38 +00:00Commented Feb 19, 2015 at 8:21
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.
Explore related questions
See similar questions with these tags.