0

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?

0

Try below code for it

$templateOptions = array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID);


        $templateVars = array(
                            'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
                            'customer_name' => 'John Doe',
                            'message'   => 'Hello World!!.'
                        );


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

        $postObject = new \Magento\Framework\DataObject();
        $postObject->setData($templateVars);

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


        $transport->sendMessage();


        $this->_inlineTranslation->resume();
  • sorry not working.. – Ravi Soni Sep 25 '18 at 7:13

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.