Magento2: Custom email template from Admin

by Ravi   Last Updated September 25, 2018 06:09 AM

I am trying to send an email to the customer once it saves from the Admin. I have called my observer "adminhtml_customer_save_after". Observer called but email template not working. my code is below.

$templateOptions = array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->_storeManager->getStore()->getId());


        $templateVars = array(
                            'store' => $this->_storeManager->getStore(),
                            'customer_name' => 'John Doe',
                            'message'   => 'Hello World!!.'
                        );


        $from = array('email' => "ravi@examle.com", 'name' => 'Ravi');
        $to = array('email' => "ravi@gmail.com", 'name' => 'Ravi');

        $this->_inlineTranslation->suspend();
        $transport = $this->_transportBuilder->setTemplateIdentifier('hello_template')
                        ->setTemplateOptions($templateOptions)
                        ->setTemplateVars($templateVars)
                        ->setFrom($from)
                        ->addTo($to)
                        ->getTransport();


        $transport->sendMessage();


        $this->_inlineTranslation->resume();

Can anyone please look and tell me what I miss?



Related Questions