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 but 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"/>

And I have this in my Post.php file

public function execute()
        $post = $this->getRequest()->getPost();
            // Send Mail
            $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
                    'area' => 'frontend',
                    'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
                    'name'  => $post['name'],
                    'lastname' => $post['lastname'],
                    'email'  => $post['email'],
                    'phone'  => $post['phone'],
                    'byphone' => $post['byphone'],
                    'bytext' => $post['bytext'],
                    'byemail' => $post['byemail']
                $this->messageManager->addSuccess('Thankyou for your appointment booking request, we will be in contact with you shortly.');
        } catch(\Exception $e){

I can see the amil template is being set by


But how do I set another template ie the video-appointment-customer.html so that sends to the customer?

  1. If you want to send a completely different email then create one more email template as you did for the customer to admin.

  2. If you want to change Dear to Dear then Pass var to the email template accordingly.

  3. Use try to use call .phtml file in template and then set condition accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.