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();

            $transport = $this->_transportBuilder
                ->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]'])

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"/>

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.

  • Which path you have the sendcredentials.html file? Apr 3, 2019 at 14:37
  • It suppose to be in view/adminhtml/email/ folder, Please verify it Apr 3, 2019 at 14:38
  • yes it is there,i commented my question Apr 3, 2019 at 14:39

1 Answer 1


I solved my self,changed area


'area' => \Magento\Framework\App\Area::AREA_FRONTEND,


'area' => \Magento\Framework\App\Area::AREA_ADMINHTML,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.