1

When I load my custom template in Marketing->Email Templates and look at the preview the email looks fine and includes the header, but when I send an email using the custom template only the footer is included, the header and css styles are not included.

How the template header and footer are added:

<!--@subject My Subject  @-->
<!--@vars {
"var customer.email":"Customer Email",
"var customer.name":"Customer Name"
} @-->

{{template config_path="design/email/header_template"}}

template content

{{template config_path="design/email/footer_template"}}
  • are you sending email using which area? – Sunil Patel Nov 25 '17 at 15:55
6

I had a slightly different problem but i think it would be good to post the solution here anyway as I came across this post when researching my issue.

I have a custom module that triggers an email on a cron. The header and footer were not being included when the emails were sent.

The header and email templates are only located in the frontend area. See : public/vendor/magento/module-email/view/

As such if your template options state 'adminhtml' or 'crontab' for example it wont find those templates.

In your custom code you will have a section or method containing something like this :

$this->transportBuilder->setTemplateIdentifier($templateId)
            ->setTemplateOptions($templateOptions)
            ->setTemplateVars($templateVars)
            ->addCc($ccs)
            ->setFrom($senderInfo)
            ->addTo($receiverInfo['email'], $receiverInfo['name']);

When you set your template options you need to make sure that you set the 'area' to be 'frontend' :

$templateOptions = array(
     'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
     'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
);

Equally, if your email template is in adminhtml/templates/email/ it will have to be moved to frontend/templates/email/

  • I am having same king of issue, I created one custom email template and i used custom theme for frontend. When I send email from custom module it was taking email of luma theme. I want it should take email template of my custom theme. After log debugging I found issue with store id – PMB Dec 8 '17 at 11:01
  • Yes, same issue getting in my email when use ADMINHTML area – Sourav Dec 22 '18 at 7:55
1

Same here.

In my case, it comes from param type in email_templates.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
    <template id="my_custom_email_id" label="My custom email label" file="my_custom_email.html" type="html" module="Vendor_Module" area="frontend"/>
</config>

I change type="text" to type="html" and it works.

Hope that helps.

0

Add 2 variables as mentioned & it works :)

<!--@subject My Subject  @-->
<!--@vars {
"var customer.email":"Customer Email",
"var customer.name":"Customer Name",
"template config_path=\"design\/email\/footer_template\"":"Email Footer Template",
"template config_path=\"design\/email\/header_template\"":"Email Header Template"
} @-->

{{template config_path="design/email/header_template"}}

template content

{{template config_path="design/email/footer_template"}}
  • Hi Ankit, i have added above code but its not working for me .. – Sarvesh Tiwari Aug 22 '17 at 5:57
  • Not working for me too – Miroslav Petroff Sep 21 '17 at 12:28
  • Anyone get anywhere with this ? – Frank Dec 1 '17 at 11:24
0

You need to set the correct store in the

 $templateOptions = array(
    'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
    'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
    );

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.