Email Functionality not Working in 2.3.0
Finally I have Found Solution and Now it's Working
$sender = [
'email' => $this->_escaper->escapeHtml($customer_email),
'name' => $this->_escaper->escapeHtml($customer_name)
];
$to_email = $this->_helper->getSendMailTo();
$transport= $this->_transportBuilder->setTemplateIdentifier('config_email_settings_email_template')
->setTemplateOptions($templateOptions)
->setTemplateVars($templateVars)
->setFrom($sender)
->addTo($to_email, 'Name')
->getTransport();
$transport->sendMessage();
Please replace your code with following code and check after clear your cache, also please remove "_escaper" from your code.
$transport = $this->transportBuilder
->setTemplateIdentifier('config_email_settings_email_template')
->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($emailSender)
->addTo($emailRecipient)
->setReplyTo($replyToEmail, $replyToName)
->getTransport();
$transport->sendMessage();
Since Magento 2.3, Magento uses Zend Framework 2 for sending emails. Which probably changed the logic used for parsing array with the recipient data.
So here are few variants on how you can properly send email in Magento 2.3:
- For multiple recipients: use array where key is the recipient's email address and value - recipient's name (note, the same rules applied to sender details):
$sender = [$this->_escaper->escapeHtml($customer_email) => $this->_escaper->escapeHtml($customer_name)];
$to_email = $this->_helper->getSendMailTo();
$sendToInfo = [$this->_escaper->escapeHtml($to_email) => 'Recipient Name'];
$transport = $this->_transportBuilder->setTemplateIdentifier('config_email_settings_email_template')
->setTemplateOptions($templateOptions)
->setTemplateVars($templateVars)
->setFrom($sender)
->addTo($sendToInfo)
->getTransport();
$transport->sendMessage();
- Or you can use the code below to send an email to a single recipient. This code is backward compatible with Magento 2.2 and lower versions:
$to_email = $this->_helper->getSendMailTo();
$transport = $this->_transportBuilder->setTemplateIdentifier('config_email_settings_email_template')
->setTemplateOptions($templateOptions)
->setTemplateVars($templateVars)
->setFrom($this->_escaper->escapeHtml($customer_email))
->addTo($this->_escaper->escapeHtml($to_email))
->getTransport();
$transport->sendMessage();