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>
- 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"}}
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;
}