5

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"}}
1
  • are you sending email using which area? Nov 25, 2017 at 15:55

4 Answers 4

13

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/

** Just want to add that this works on a single store configuration. If you are using multi-store configuration. You will need to pull the store id via a different mechanism, like:

$order->getStoreId();
3
  • 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 Dec 8, 2017 at 11:01
  • Yes, same issue getting in my email when use ADMINHTML area
    – Sourav
    Dec 22, 2018 at 7:55
  • Thank you for the explanation, It helped alot understanding the mechanism.
    – Rayed
    Nov 17, 2021 at 15:39
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"}}
3
  • Hi Ankit, i have added above code but its not working for me .. Aug 22, 2017 at 5:57
  • Not working for me too Sep 21, 2017 at 12:28
  • Anyone get anywhere with this ?
    – Frank
    Dec 1, 2017 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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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