Send email using helper class but getting below error
TypeError: Magento\Email\Model\Template::setVars(): Argument #1 ($vars) must be of type array, null given
My code is,
<?php
namespace Custom\ScheduleContentNotifier\Helper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Translate\Inline\StateInterface;
use Magento\Framework\Escaper;
use Magento\Framework\Mail\Template\TransportBuilder;
class Email extends \Magento\Framework\App\Helper\AbstractHelper
{
protected $inlineTranslation;
protected $escaper;
protected $transportBuilder;
protected $logger;
public function __construct(
Context $context,
StateInterface $inlineTranslation,
Escaper $escaper,
TransportBuilder $transportBuilder
) {
parent::__construct($context);
$this->inlineTranslation = $inlineTranslation;
$this->escaper = $escaper;
$this->transportBuilder = $transportBuilder;
$this->logger = $context->getLogger();
}
public function sendEmail()
{
try {
$this->inlineTranslation->suspend();
$sender = [
'name' => $this->escaper->escapeHtml('Test'),
'email' => $this->escaper->escapeHtml('[email protected]'),
];
$transport = $this->transportBuilder
->setTemplateIdentifier('content_update_template')
->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
]
)
->setFrom($sender)
->addTo('[email protected]')
->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
} catch (\Exception $e) {
$this->logger->debug($e->getMessage());
}
}
}