I have my custom module on Magento 2.3 and my custom module should send email from frontend. On this code, the module stops working
$transportToStore = $this->transportBuilder ->setTemplateIdentifier('send_pro_email_store_template')
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI have my custom module on Magento 2.3 and my custom module should send email from frontend. On this code, the module stops working
$transportToStore = $this->transportBuilder ->setTemplateIdentifier('send_pro_email_store_template')
Defin Variable protected $_transportBuilder;
In __construct
Define \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
And Define $this->_transportBuilder = $transportBuilder;
In Your File :-
protected $_transportBuilder;
public function __construct(
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
array $data = []
){
$this->_transportBuilder = $transportBuilder;
parent::__construct($data);
}
public function yourFunction()
{
$transport = $this->_transportBuilder->setTemplateIdentifier('send_pro_email_store_template')
->setTemplateOptions($templateOptions)
->setTemplateVars($templateVars)
->setFrom($from)
->addTo($to)
->addBcc($bcc)
->getTransport();
$transport->sendMessage();
}