1

I have created Contact template but not display header and footer. below my code for contact html.

<!--@subject {{trans "Contact Form"}} @--> <!--@vars { "var
data.comment":"Comment", "var data.email":"Sender Email", "var
data.name":"Sender Name", "var data.telephone":"Sender Telephone" }
@-->

<!--@vars { "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"}}

<table>
    <tr>
        <td>{{trans "Name: %name" name=$data.name}}</td>
    </tr>
    <tr>
        <td>{{trans "Email: %email" email=$data.email}}</td>
    </tr>
    <tr>
        <td>{{trans "Phone Number: %telephone" telephone=$data.telephone}}</td>
    </tr>
    <tr>
        <td>{{trans "Comment: %comment" comment=$data.comment}}</td>
    </tr> 
</table>

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

2 Answers 2

2

Create Files in module 1. Packgesname/modulename/etc/email_templates.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Mypackages_Mymodule:etc/email_templates.xsd">
    <template id="contact_general_template" label="Contact" file="contact_dd.html" type="html" module="Mypackages_Mymodule" area="frontend"/>
</config>
  1. Packagesname/modulename/view/frontend/email/contact_dd.html
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
 <!--@subject {{trans "Contact Form"}} @--> <!--@vars { 
    "var data.comment":"Comment", "var data.email":"Sender Email", 
     "var data.name":"Sender Name", "var data.telephone":"Sender Telephone",
     "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"}}
<table>
    <tr>
        <td>{{trans "Name: %name" name=$data.name}}</td>
    </tr>
    <tr>
        <td>{{trans "Email: %email" email=$data.email}}</td>
    </tr>
    <tr>
        <td>{{trans "Phone Number: %telephone" telephone=$data.telephone}}</td>
    </tr>
    <tr>
        <td>{{trans "Comment: %comment" comment=$data.comment}}</td>
    </tr>
</table>
{{template config_path="design/email/footer_template"}}
  1. override file Magento\Contact\Controller\Index\Post

    $post = $this->getRequest()->getPostValue();
            if (!$post) {
                $this->_redirect('*/*/');
                return;
            }
    
        $this->inlineTranslation->suspend();
        try {
            $postObject = new \Magento\Framework\DataObject();
            $postObject->setData($post);
    
            $error = false;
    
            if (!\Zend_Validate::is(trim($post['name']), 'NotEmpty')) {
                $error = true;
            }
            if (!\Zend_Validate::is(trim($post['comment']), 'NotEmpty')) {
                $error = true;
            }
            if (!\Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                $error = true;
            }
            if (\Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
                $error = true;
            }
            if ($error) {
                throw new \Exception();
            }
        $storeId = $this->storeManager->getStore()->getId();
            $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
            $transport = $this->_transportBuilder
                ->setTemplateIdentifier($this->scopeConfig->getValue(self::XML_PATH_EMAIL_TEMPLATE, $storeScope))
                ->setTemplateOptions(
                    [
                        'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
                        'store' => $storeId,
                    ]
                )
                ->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();
    
            $transport->sendMessage();
            $this->inlineTranslation->resume();
            $this->messageManager->addSuccess(
                __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.')
            );
            $this->getDataPersistor()->clear('contact_us');
            $this->_redirect('contact/index');
            return;
        } catch (\Exception $e) {
            $this->inlineTranslation->resume();
            $this->messageManager->addError(
                __('We can\'t process your request right now. Sorry, that\'s all we know.')
            );
            $this->getDataPersistor()->set('contact_us', $post);
            $this->_redirect('contact/index');
            return;
        }
    
2

Only use

<!--@subject {{trans "Contact Form"}} @--> 
<!--@vars { 
    "var data.comment":"Comment", "var data.email":"Sender Email", 
    "var data.name":"Sender Name", "var data.telephone":"Sender Telephone",
    "template config_path=\"design\/email\/footer_template\"":"Email Footer Template", 
    "template config_path=\"design\/email\/header_template\"":"Email Header Template"
    }
 @-->

Then run

php bin/magento setup:di:compile
9
  • php bin/magento setup:di:compile any risk with this command?
    – Ajay Patel
    Jun 22, 2017 at 8:31
  • Nope. No risk @AjayPatel
    – Jackson
    Jun 22, 2017 at 8:32
  • I have run but not work?
    – Ajay Patel
    Jun 22, 2017 at 8:34
  • send only content without header footer
    – Ajay Patel
    Jun 22, 2017 at 8:34
  • Run commands in order php bin/magento setup:upgrade, php bin/magento setup:di:compile, php bin/magento setup:static-content:deploy, php bin/magento indexer:reindex, php bin/magento cache:flush
    – Jackson
    Jun 22, 2017 at 8:37

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.