І will try to send email but when i set the parameters for transportBuilder the page just reloads.
Through var_dump I learned that the page reloads before the sendMassage method. For the sender and recipient fields, I tried to set the value simply through a string.
Locatiion of email_templates = Vendor/Module/etc/email_templates Location of email template file = Vendor/Module/view/email/template.html
//Controller action
$this->inlineTranslation->suspend();
$storeScope = ScopeInterface::SCOPE_STORE;
$transport = $this->transportBuilder
->setTemplateIdentifier('request_admin_email_answer_template')
->setTemplateOptions(
[
'area' => FrontNameResolver::AREA_CODE,
'store' => Store::DEFAULT_STORE_ID,
]
)
->setTemplateVars(['data' => $postObject])
->setFrom($this->scopeConfig->getValue(self::XML_SENDER_EMAIL, $storeScope))
->addTo($model->getEmail());
$transport = $transport->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
//email_templates.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
<template id="request_admin_email_answer_template" label="Request price Answer" file="request_price_answer.html" type="text" module="Smile_Customer" area="adminhtml"/>
</config>
//request_price_answer.html
{{trans "Name: %name" name=$data.name}}
{{trans "Email: %email" email=$data.email}}
{{trans "Your Request: %comment" comment=$data.comment}}
{{trans "Answer for your request: %answer" answer=$data.answer_content}}
As a result, the email should go, but for now the page just reloads.