1

I followed below answer but could not override default contact us email template.

Magento 2: How to change Contact Us Email Type?

I developed extension to override form.phtml to add new contact us fields. Now I want to add those custom fields in contact us email template. I tried as per above solution but it always use default contact us email template.

0

You need to override controller which sends email for contact us form. Magento\Contact\Controller\Index\Post.php

In this file line number around 57 you will get a code which sets template id.

$transport = $this->_transportBuilder
                ->setTemplateIdentifier(<YOUR_EMAIL_TEMPLATE_ID > )
                ->setTemplateOptions(
                    [
                        'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
                        'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
                    ]
                )
                ->setTemplateVars(['data' => $postObject])
                ->setFrom($this->scopeConfig->getValue(self::XML_PATH_EMAIL_SENDER, $storeScope))
                ->addTo($this->scopeConfig->getValue(self::XML_PATH_EMAIL_RECIPIENT, $storeScope))
                ->setReplyTo($post['email'])
                ->getTransport();

In this code replace it with your email template id. so your email template will be used to send emails.

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.