I have a custom module which is a custom form for the user to book an appointment, this form works fine with no issues, the form once submitted sends and email to both the admin and user/customer but it uses the same template. What I'd like is the customer to receive a different email with a success message etc.
I have this is my email_templates.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
<template id="video-appointment" label="Video Appointment Form" file="video-appointment.html" type="html" module="VideoAppointment_Appointmentform" area="frontend"/>
<template id="video-appointment-customer" label="Video Appointment Success" file="video-appointment-customer.html" type="html" module="VideoAppointment_Appointmentform" area="frontend"/>
</config>
And I have this in my Post.php file
public function execute()
{
$post = $this->getRequest()->getPost();
try
{
// Send Mail
$this->_inlineTranslation->suspend();
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
$sender = [
'name' => $post['name'],
'lastname' => $post['lastname'],
'email' => $post['email'],
'phone' => $post['phone'],
'byphone' => $post['byphone'],
'bytext' => $post['bytext'],
'byemail' => $post['byemail']
];
$sentToEmail = $this->_scopeConfig ->getValue('trans_email/ident_custom1/email',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$sentToName = $this->_scopeConfig ->getValue('trans_email/ident_custom1/name',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$transport = $this->_transportBuilder
->setTemplateIdentifier('video-appointment')
->setTemplateOptions(
[
'area' => 'frontend',
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
]
)
->setTemplateVars([
'name' => $post['name'],
'lastname' => $post['lastname'],
'email' => $post['email'],
'phone' => $post['phone'],
'byphone' => $post['byphone'],
'bytext' => $post['bytext'],
'byemail' => $post['byemail']
])
->setFrom($sender)
->addTo($sentToEmail,$sentToName)
->addBcc($post['email'])
//->addTo('[email protected]','owner')
->getTransport();
$transport->sendMessage();
$this->_inlineTranslation->resume();
$this->messageManager->addSuccess('Thankyou for your appointment booking request, we will be in contact with you shortly.');
$this->_redirect('video-appointment/index/index');
} catch(\Exception $e){
$this->messageManager->addError($e->getMessage());
$this->_logLoggerInterface->debug($e->getMessage());
exit;
}
I can see the email template is being set by
->setTemplateIdentifier('video-appointment')
But how do I set another template (ie the video-appointment-customer.html
) to send to the customer?