_objectManager = ObjectManager::getInstance(); $this->_escaper = $escaper; $this->_inlineTranslation = $inlineTranslation; $this->_transportBuilder = $transportBuilder; $this->_urlInterface = $urlInterface; $this->_messageManager = $messageManager; parent::__construct($context, $data); } public function execute() { $data = $this->getRequest()->getPostValue(); if(!empty($data)) { $scopeConfig = $this->_objectManager->create('\Magento\Framework\App\Config\ScopeConfigInterface'); $email_contact = $scopeConfig->getValue('trans_email/ident_general/email',\Magento\Store\Model\ScopeInterface::SCOPE_STORE); $this->_inlineTranslation->suspend(); $sender = [ "name" => $this->_escaper->escapeHtml($data["contact"]), "email" => $this->_escaper->escapeHtml($data["email"]) ]; $transport = $this->_transportBuilder ->setTemplateIdentifier('email_asset_rental_template') ->setTemplateOptions( [ 'area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, ] ) ->setTemplateVars([ 'title' => $this->getData("rental_title"), 'name' => $data["contact"], 'email' => $data["email"], 'phone' => $data["phone"], 'company' => $data["company"], 'enquiry' => $data["enquiry"] ]) ->setFrom($sender) ->addTo($email_contact) ->getTransport(); $transport->sendMessage(); $this->_inlineTranslation->resume(); $this->_messageManager->addSuccess(__("Thanks you. We'll respond to you very soon.")); } } function getAssetUrl($asset) { $assetRepository = $this->_objectManager->get('Magento\Framework\View\Asset\Repository'); return $assetRepository->createAsset($asset)->getUrl(); } function getBaseUrl() { $storeManager = $this->_objectManager->get('\Magento\Store\Model\StoreManagerInterface'); $baseUrl = $storeManager->getStore()->getBaseUrl(); return $baseUrl; } function getCurrentURL() { return $this->_urlInterface->getCurrentUrl(); } }