1

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"/>
     
</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('owner@example.com','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 amil template is being set by

->setTemplateIdentifier('video-appointment')

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

0
  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.