Magento 2 send email(adminhtml) programatically not working. i am using this code -
$report = [
'report_date' => date("j F Y", strtotime('-1 day')),
'orders_count' => rand(1, 10),
'order_items_count' => rand(1, 10),
'avg_items' => rand(1, 10)
];
$postObject = new \Magento\Framework\DataObject();
$postObject->setData($report);
$transport = $this->_transportBuilder
->setTemplateIdentifier('sendcredentials')
->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
->setTemplateVars(['data' => $postObject])
->setFrom(['name' => 'Robot','email' => '[email protected]'])
->addTo(['[email protected]', '[email protected]'])
->getTransport();
$transport->sendMessage();
and email_templates.xml(location-etc)
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:Magento:module:Magento_Email:etc/email_templates.xsd">
<template id="sendcredentials" label="Test email" file="sendcredentials.html" type="html" module="Vendor_Sendcredentials" area="adminhtml"/>
</config>
and HTML file sendcredentials.html(location-view/adminhtml/email) -
<!--@subject Custom @-->
<h3>Report from {{var data.report_date|raw}}</h3>
<p><b>Number of orders:</b> {{var data.orders_count|raw}}</p>
<p><b>Items count:</b> {{var data.order_items_count|raw}}</p>
<p><b>Average items per order:</b> {{var data.avg_items|raw}}</p>
I am getting this error -
Template file 'sendcredentials.html' is not found.