Send transactional email from root folder magento 2Magento2 get email templates dropdown in stores configurationMagento transactional email shows and old template even after styling itCreate transactional email via install/upgrade scriptSend email with magentoTransactional email templates not loadingOverriding send email functions with custom functionsMagento transactional email template variables assigned are not used by templateMagento2- Send custom transactional emailsMagento 2 Transactional Email VariablesMagento send Custom emailMagento transactional email new order email template product image missing

Is the destination of a commercial flight important for the pilot?

How can a function with a hole (removable discontinuity) equal a function with no hole?

Anatomically Correct Strange Women In Ponds Distributing Swords

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

Is expanding the research of a group into machine learning as a PhD student risky?

Large drywall patch supports

System.debug(JSON.Serialize(o)) Not longer shows full string

How does the UK government determine the size of a mandate?

Lay out the Carpet

Sequence of Tenses: Translating the subjunctive

How did Arya survive the stabbing?

How do I rename a Linux host without needing to reboot for the rename to take effect?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

What can we do to stop prior company from asking us questions?

A problem in Probability theory

Implement the Thanos sorting algorithm

How do I extract a value from a time formatted value in excel?

Pre-amplifier input protection

What is the best translation for "slot" in the context of multiplayer video games?

How to be diplomatic in refusing to write code that breaches the privacy of our users

How to pronounce the slash sign

Energy of the particles in the particle accelerator

Crossing the line between justified force and brutality

Sort a list by elements of another list



Send transactional email from root folder magento 2


Magento2 get email templates dropdown in stores configurationMagento transactional email shows and old template even after styling itCreate transactional email via install/upgrade scriptSend email with magentoTransactional email templates not loadingOverriding send email functions with custom functionsMagento transactional email template variables assigned are not used by templateMagento2- Send custom transactional emailsMagento 2 Transactional Email VariablesMagento send Custom emailMagento transactional email new order email template product image missing













3















How to send transactional email template from Magento 2 root folder?










share|improve this question




























    3















    How to send transactional email template from Magento 2 root folder?










    share|improve this question


























      3












      3








      3








      How to send transactional email template from Magento 2 root folder?










      share|improve this question
















      How to send transactional email template from Magento 2 root folder?







      magento2 email-templates






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 24 '17 at 9:30









      Teja Bhagavan Kollepara

      3,01141949




      3,01141949










      asked Jul 12 '17 at 9:38









      RaghuRaghu

      1,2861520




      1,2861520




















          2 Answers
          2






          active

          oldest

          votes


















          5














          Developed a module for email setup by referring the blog for the requirement: https://webkul.com/blog/magento-2-send-transactional-email-programmatically-in-your-custom-module/



          Here I have modified the helper class according the usage as follows:



          <?php
          namespace VendorNameCustomModuleHelper;

          use MagentoFrameworkAppArea;

          class Emailreport extends MagentoFrameworkAppHelperAbstractHelper

          /**
          * @var MagentoFrameworkAppConfigScopeConfigInterface
          */
          protected $_scopeConfig;
          /**
          * Store manager
          *
          * @var MagentoStoreModelStoreManagerInterface
          */
          protected $_storeManager;
          /**
          * @var MagentoFrameworkTranslateInlineStateInterface
          */
          protected $inlineTranslation;
          /**
          * @var MagentoFrameworkMailTemplateTransportBuilder
          */
          protected $_transportBuilder;

          /**
          * @param MagentoFrameworkAppHelperContext $context
          * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
          * @param MagentoStoreModelStoreManagerInterface $storeManager
          * @param MagentoFrameworkTranslateInlineStateInterface $inlineTranslation
          * @param MagentoFrameworkMailTemplateTransportBuilder $transportBuilder
          */
          public function __construct(
          MagentoFrameworkAppHelperContext $context,
          MagentoStoreModelStoreManagerInterface $storeManager,
          MagentoFrameworkTranslateInlineStateInterface $inlineTranslation,
          MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
          MagentoFrameworkAppState $state
          )
          $this->_scopeConfig = $context;
          parent::__construct($context);
          $this->_storeManager = $storeManager;
          $this->inlineTranslation = $inlineTranslation;
          $this->_transportBuilder = $transportBuilder;
          $state->setAreaCode('frontend');

          /**
          * @param string $path
          * @param int $storeId
          * @return mixed
          */
          protected function getConfigValue($path, $storeId)

          return $this->scopeConfig->getValue(
          $path,
          MagentoStoreModelScopeInterface::SCOPE_STORE,
          $storeId
          );

          /**
          * Return store
          *
          * @return Store
          */
          public function getStore()

          return $this->_storeManager->getStore();


          public function sendEmailReport(
          $template,
          $senderInfo,
          $receiverInfo,
          $templateParams = []
          )
          $this->inlineTranslation->suspend();
          $templateId = $this->getConfigValue($template, $this->getStore()->getStoreId());

          $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)
          ->setTemplateOptions(
          [
          'area' => Area::AREA_FRONTEND,
          'store' => $this->getStore()->getId(),
          ]
          )
          ->setTemplateVars($templateParams)
          ->setFrom($senderInfo)
          ->addTo($receiverInfo['email'],$receiverInfo['name'])
          ->getTransport();

          $transport->sendMessage();
          $this->inlineTranslation->resume();

          return $this;




          Now using the following code we can able to trigger the email from root folder:



          <?php 
          use MagentoFrameworkAppBootstrap;
          require __DIR__ . '/app/bootstrap.php';
          $bootstrap = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrap->getObjectManager();

          $customEmailPath = 'contact/email/email_template'; // section_id/group_id/field_id

          /* Sender Detail */
          $senderInfo = [
          'name' => 'sender',
          'email' => 'sender@domain.com'
          ];

          /* Receiver Detail */
          $receiverInfo = [
          'name' => 'receiver',
          'email' => 'receiver@domain.com'
          ];

          /* To assign the values to template variables */

          $customerDetails = array();
          $customerDetails['name'] = 'John Doe';
          $customerDetails['email'] = 'test@example.com';



          $objectManager->get('VendorNameCustomModuleHelperEmailreport')->sendEmailReport(
          $customEmailPath,
          $senderInfo,
          $receiverInfo,
          $customerDetails = []
          );





          share|improve this answer

























          • what should we configure here----$customEmailPath = 'section_id/group_id/field_id';

            – Raghu
            Jul 12 '17 at 10:36











          • For instance if we need the email template format of new sales order email give 'sales_email/order/template' . This field can be identified from /vendor/magento/module-sales/etc/adminhtml/system.xml

            – Haritha
            Jul 12 '17 at 10:43











          • we have given the transactional email ID there directly

            – Raghu
            Jul 12 '17 at 10:47











          • but we are getting this error Fatal error: Uncaught Error: Call to protected method NamespaceModulenameHelperEmailreport::sendEmailReport() from context '' in customtest.php:33 Stack trace: #0 main thrown in customtest.php on line 33

            – Raghu
            Jul 12 '17 at 10:47












          • Please check the updated code.

            – Haritha
            Jul 12 '17 at 11:57


















          0














          I have created above two mentioned file. I have run file on root. I am getting null values in email template as below image.
          enter image description here





          share








          New contributor




          Dinesh Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.



















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f183281%2fsend-transactional-email-from-root-folder-magento-2%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            5














            Developed a module for email setup by referring the blog for the requirement: https://webkul.com/blog/magento-2-send-transactional-email-programmatically-in-your-custom-module/



            Here I have modified the helper class according the usage as follows:



            <?php
            namespace VendorNameCustomModuleHelper;

            use MagentoFrameworkAppArea;

            class Emailreport extends MagentoFrameworkAppHelperAbstractHelper

            /**
            * @var MagentoFrameworkAppConfigScopeConfigInterface
            */
            protected $_scopeConfig;
            /**
            * Store manager
            *
            * @var MagentoStoreModelStoreManagerInterface
            */
            protected $_storeManager;
            /**
            * @var MagentoFrameworkTranslateInlineStateInterface
            */
            protected $inlineTranslation;
            /**
            * @var MagentoFrameworkMailTemplateTransportBuilder
            */
            protected $_transportBuilder;

            /**
            * @param MagentoFrameworkAppHelperContext $context
            * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
            * @param MagentoStoreModelStoreManagerInterface $storeManager
            * @param MagentoFrameworkTranslateInlineStateInterface $inlineTranslation
            * @param MagentoFrameworkMailTemplateTransportBuilder $transportBuilder
            */
            public function __construct(
            MagentoFrameworkAppHelperContext $context,
            MagentoStoreModelStoreManagerInterface $storeManager,
            MagentoFrameworkTranslateInlineStateInterface $inlineTranslation,
            MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
            MagentoFrameworkAppState $state
            )
            $this->_scopeConfig = $context;
            parent::__construct($context);
            $this->_storeManager = $storeManager;
            $this->inlineTranslation = $inlineTranslation;
            $this->_transportBuilder = $transportBuilder;
            $state->setAreaCode('frontend');

            /**
            * @param string $path
            * @param int $storeId
            * @return mixed
            */
            protected function getConfigValue($path, $storeId)

            return $this->scopeConfig->getValue(
            $path,
            MagentoStoreModelScopeInterface::SCOPE_STORE,
            $storeId
            );

            /**
            * Return store
            *
            * @return Store
            */
            public function getStore()

            return $this->_storeManager->getStore();


            public function sendEmailReport(
            $template,
            $senderInfo,
            $receiverInfo,
            $templateParams = []
            )
            $this->inlineTranslation->suspend();
            $templateId = $this->getConfigValue($template, $this->getStore()->getStoreId());

            $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)
            ->setTemplateOptions(
            [
            'area' => Area::AREA_FRONTEND,
            'store' => $this->getStore()->getId(),
            ]
            )
            ->setTemplateVars($templateParams)
            ->setFrom($senderInfo)
            ->addTo($receiverInfo['email'],$receiverInfo['name'])
            ->getTransport();

            $transport->sendMessage();
            $this->inlineTranslation->resume();

            return $this;




            Now using the following code we can able to trigger the email from root folder:



            <?php 
            use MagentoFrameworkAppBootstrap;
            require __DIR__ . '/app/bootstrap.php';
            $bootstrap = Bootstrap::create(BP, $_SERVER);
            $objectManager = $bootstrap->getObjectManager();

            $customEmailPath = 'contact/email/email_template'; // section_id/group_id/field_id

            /* Sender Detail */
            $senderInfo = [
            'name' => 'sender',
            'email' => 'sender@domain.com'
            ];

            /* Receiver Detail */
            $receiverInfo = [
            'name' => 'receiver',
            'email' => 'receiver@domain.com'
            ];

            /* To assign the values to template variables */

            $customerDetails = array();
            $customerDetails['name'] = 'John Doe';
            $customerDetails['email'] = 'test@example.com';



            $objectManager->get('VendorNameCustomModuleHelperEmailreport')->sendEmailReport(
            $customEmailPath,
            $senderInfo,
            $receiverInfo,
            $customerDetails = []
            );





            share|improve this answer

























            • what should we configure here----$customEmailPath = 'section_id/group_id/field_id';

              – Raghu
              Jul 12 '17 at 10:36











            • For instance if we need the email template format of new sales order email give 'sales_email/order/template' . This field can be identified from /vendor/magento/module-sales/etc/adminhtml/system.xml

              – Haritha
              Jul 12 '17 at 10:43











            • we have given the transactional email ID there directly

              – Raghu
              Jul 12 '17 at 10:47











            • but we are getting this error Fatal error: Uncaught Error: Call to protected method NamespaceModulenameHelperEmailreport::sendEmailReport() from context '' in customtest.php:33 Stack trace: #0 main thrown in customtest.php on line 33

              – Raghu
              Jul 12 '17 at 10:47












            • Please check the updated code.

              – Haritha
              Jul 12 '17 at 11:57















            5














            Developed a module for email setup by referring the blog for the requirement: https://webkul.com/blog/magento-2-send-transactional-email-programmatically-in-your-custom-module/



            Here I have modified the helper class according the usage as follows:



            <?php
            namespace VendorNameCustomModuleHelper;

            use MagentoFrameworkAppArea;

            class Emailreport extends MagentoFrameworkAppHelperAbstractHelper

            /**
            * @var MagentoFrameworkAppConfigScopeConfigInterface
            */
            protected $_scopeConfig;
            /**
            * Store manager
            *
            * @var MagentoStoreModelStoreManagerInterface
            */
            protected $_storeManager;
            /**
            * @var MagentoFrameworkTranslateInlineStateInterface
            */
            protected $inlineTranslation;
            /**
            * @var MagentoFrameworkMailTemplateTransportBuilder
            */
            protected $_transportBuilder;

            /**
            * @param MagentoFrameworkAppHelperContext $context
            * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
            * @param MagentoStoreModelStoreManagerInterface $storeManager
            * @param MagentoFrameworkTranslateInlineStateInterface $inlineTranslation
            * @param MagentoFrameworkMailTemplateTransportBuilder $transportBuilder
            */
            public function __construct(
            MagentoFrameworkAppHelperContext $context,
            MagentoStoreModelStoreManagerInterface $storeManager,
            MagentoFrameworkTranslateInlineStateInterface $inlineTranslation,
            MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
            MagentoFrameworkAppState $state
            )
            $this->_scopeConfig = $context;
            parent::__construct($context);
            $this->_storeManager = $storeManager;
            $this->inlineTranslation = $inlineTranslation;
            $this->_transportBuilder = $transportBuilder;
            $state->setAreaCode('frontend');

            /**
            * @param string $path
            * @param int $storeId
            * @return mixed
            */
            protected function getConfigValue($path, $storeId)

            return $this->scopeConfig->getValue(
            $path,
            MagentoStoreModelScopeInterface::SCOPE_STORE,
            $storeId
            );

            /**
            * Return store
            *
            * @return Store
            */
            public function getStore()

            return $this->_storeManager->getStore();


            public function sendEmailReport(
            $template,
            $senderInfo,
            $receiverInfo,
            $templateParams = []
            )
            $this->inlineTranslation->suspend();
            $templateId = $this->getConfigValue($template, $this->getStore()->getStoreId());

            $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)
            ->setTemplateOptions(
            [
            'area' => Area::AREA_FRONTEND,
            'store' => $this->getStore()->getId(),
            ]
            )
            ->setTemplateVars($templateParams)
            ->setFrom($senderInfo)
            ->addTo($receiverInfo['email'],$receiverInfo['name'])
            ->getTransport();

            $transport->sendMessage();
            $this->inlineTranslation->resume();

            return $this;




            Now using the following code we can able to trigger the email from root folder:



            <?php 
            use MagentoFrameworkAppBootstrap;
            require __DIR__ . '/app/bootstrap.php';
            $bootstrap = Bootstrap::create(BP, $_SERVER);
            $objectManager = $bootstrap->getObjectManager();

            $customEmailPath = 'contact/email/email_template'; // section_id/group_id/field_id

            /* Sender Detail */
            $senderInfo = [
            'name' => 'sender',
            'email' => 'sender@domain.com'
            ];

            /* Receiver Detail */
            $receiverInfo = [
            'name' => 'receiver',
            'email' => 'receiver@domain.com'
            ];

            /* To assign the values to template variables */

            $customerDetails = array();
            $customerDetails['name'] = 'John Doe';
            $customerDetails['email'] = 'test@example.com';



            $objectManager->get('VendorNameCustomModuleHelperEmailreport')->sendEmailReport(
            $customEmailPath,
            $senderInfo,
            $receiverInfo,
            $customerDetails = []
            );





            share|improve this answer

























            • what should we configure here----$customEmailPath = 'section_id/group_id/field_id';

              – Raghu
              Jul 12 '17 at 10:36











            • For instance if we need the email template format of new sales order email give 'sales_email/order/template' . This field can be identified from /vendor/magento/module-sales/etc/adminhtml/system.xml

              – Haritha
              Jul 12 '17 at 10:43











            • we have given the transactional email ID there directly

              – Raghu
              Jul 12 '17 at 10:47











            • but we are getting this error Fatal error: Uncaught Error: Call to protected method NamespaceModulenameHelperEmailreport::sendEmailReport() from context '' in customtest.php:33 Stack trace: #0 main thrown in customtest.php on line 33

              – Raghu
              Jul 12 '17 at 10:47












            • Please check the updated code.

              – Haritha
              Jul 12 '17 at 11:57













            5












            5








            5







            Developed a module for email setup by referring the blog for the requirement: https://webkul.com/blog/magento-2-send-transactional-email-programmatically-in-your-custom-module/



            Here I have modified the helper class according the usage as follows:



            <?php
            namespace VendorNameCustomModuleHelper;

            use MagentoFrameworkAppArea;

            class Emailreport extends MagentoFrameworkAppHelperAbstractHelper

            /**
            * @var MagentoFrameworkAppConfigScopeConfigInterface
            */
            protected $_scopeConfig;
            /**
            * Store manager
            *
            * @var MagentoStoreModelStoreManagerInterface
            */
            protected $_storeManager;
            /**
            * @var MagentoFrameworkTranslateInlineStateInterface
            */
            protected $inlineTranslation;
            /**
            * @var MagentoFrameworkMailTemplateTransportBuilder
            */
            protected $_transportBuilder;

            /**
            * @param MagentoFrameworkAppHelperContext $context
            * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
            * @param MagentoStoreModelStoreManagerInterface $storeManager
            * @param MagentoFrameworkTranslateInlineStateInterface $inlineTranslation
            * @param MagentoFrameworkMailTemplateTransportBuilder $transportBuilder
            */
            public function __construct(
            MagentoFrameworkAppHelperContext $context,
            MagentoStoreModelStoreManagerInterface $storeManager,
            MagentoFrameworkTranslateInlineStateInterface $inlineTranslation,
            MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
            MagentoFrameworkAppState $state
            )
            $this->_scopeConfig = $context;
            parent::__construct($context);
            $this->_storeManager = $storeManager;
            $this->inlineTranslation = $inlineTranslation;
            $this->_transportBuilder = $transportBuilder;
            $state->setAreaCode('frontend');

            /**
            * @param string $path
            * @param int $storeId
            * @return mixed
            */
            protected function getConfigValue($path, $storeId)

            return $this->scopeConfig->getValue(
            $path,
            MagentoStoreModelScopeInterface::SCOPE_STORE,
            $storeId
            );

            /**
            * Return store
            *
            * @return Store
            */
            public function getStore()

            return $this->_storeManager->getStore();


            public function sendEmailReport(
            $template,
            $senderInfo,
            $receiverInfo,
            $templateParams = []
            )
            $this->inlineTranslation->suspend();
            $templateId = $this->getConfigValue($template, $this->getStore()->getStoreId());

            $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)
            ->setTemplateOptions(
            [
            'area' => Area::AREA_FRONTEND,
            'store' => $this->getStore()->getId(),
            ]
            )
            ->setTemplateVars($templateParams)
            ->setFrom($senderInfo)
            ->addTo($receiverInfo['email'],$receiverInfo['name'])
            ->getTransport();

            $transport->sendMessage();
            $this->inlineTranslation->resume();

            return $this;




            Now using the following code we can able to trigger the email from root folder:



            <?php 
            use MagentoFrameworkAppBootstrap;
            require __DIR__ . '/app/bootstrap.php';
            $bootstrap = Bootstrap::create(BP, $_SERVER);
            $objectManager = $bootstrap->getObjectManager();

            $customEmailPath = 'contact/email/email_template'; // section_id/group_id/field_id

            /* Sender Detail */
            $senderInfo = [
            'name' => 'sender',
            'email' => 'sender@domain.com'
            ];

            /* Receiver Detail */
            $receiverInfo = [
            'name' => 'receiver',
            'email' => 'receiver@domain.com'
            ];

            /* To assign the values to template variables */

            $customerDetails = array();
            $customerDetails['name'] = 'John Doe';
            $customerDetails['email'] = 'test@example.com';



            $objectManager->get('VendorNameCustomModuleHelperEmailreport')->sendEmailReport(
            $customEmailPath,
            $senderInfo,
            $receiverInfo,
            $customerDetails = []
            );





            share|improve this answer















            Developed a module for email setup by referring the blog for the requirement: https://webkul.com/blog/magento-2-send-transactional-email-programmatically-in-your-custom-module/



            Here I have modified the helper class according the usage as follows:



            <?php
            namespace VendorNameCustomModuleHelper;

            use MagentoFrameworkAppArea;

            class Emailreport extends MagentoFrameworkAppHelperAbstractHelper

            /**
            * @var MagentoFrameworkAppConfigScopeConfigInterface
            */
            protected $_scopeConfig;
            /**
            * Store manager
            *
            * @var MagentoStoreModelStoreManagerInterface
            */
            protected $_storeManager;
            /**
            * @var MagentoFrameworkTranslateInlineStateInterface
            */
            protected $inlineTranslation;
            /**
            * @var MagentoFrameworkMailTemplateTransportBuilder
            */
            protected $_transportBuilder;

            /**
            * @param MagentoFrameworkAppHelperContext $context
            * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
            * @param MagentoStoreModelStoreManagerInterface $storeManager
            * @param MagentoFrameworkTranslateInlineStateInterface $inlineTranslation
            * @param MagentoFrameworkMailTemplateTransportBuilder $transportBuilder
            */
            public function __construct(
            MagentoFrameworkAppHelperContext $context,
            MagentoStoreModelStoreManagerInterface $storeManager,
            MagentoFrameworkTranslateInlineStateInterface $inlineTranslation,
            MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
            MagentoFrameworkAppState $state
            )
            $this->_scopeConfig = $context;
            parent::__construct($context);
            $this->_storeManager = $storeManager;
            $this->inlineTranslation = $inlineTranslation;
            $this->_transportBuilder = $transportBuilder;
            $state->setAreaCode('frontend');

            /**
            * @param string $path
            * @param int $storeId
            * @return mixed
            */
            protected function getConfigValue($path, $storeId)

            return $this->scopeConfig->getValue(
            $path,
            MagentoStoreModelScopeInterface::SCOPE_STORE,
            $storeId
            );

            /**
            * Return store
            *
            * @return Store
            */
            public function getStore()

            return $this->_storeManager->getStore();


            public function sendEmailReport(
            $template,
            $senderInfo,
            $receiverInfo,
            $templateParams = []
            )
            $this->inlineTranslation->suspend();
            $templateId = $this->getConfigValue($template, $this->getStore()->getStoreId());

            $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)
            ->setTemplateOptions(
            [
            'area' => Area::AREA_FRONTEND,
            'store' => $this->getStore()->getId(),
            ]
            )
            ->setTemplateVars($templateParams)
            ->setFrom($senderInfo)
            ->addTo($receiverInfo['email'],$receiverInfo['name'])
            ->getTransport();

            $transport->sendMessage();
            $this->inlineTranslation->resume();

            return $this;




            Now using the following code we can able to trigger the email from root folder:



            <?php 
            use MagentoFrameworkAppBootstrap;
            require __DIR__ . '/app/bootstrap.php';
            $bootstrap = Bootstrap::create(BP, $_SERVER);
            $objectManager = $bootstrap->getObjectManager();

            $customEmailPath = 'contact/email/email_template'; // section_id/group_id/field_id

            /* Sender Detail */
            $senderInfo = [
            'name' => 'sender',
            'email' => 'sender@domain.com'
            ];

            /* Receiver Detail */
            $receiverInfo = [
            'name' => 'receiver',
            'email' => 'receiver@domain.com'
            ];

            /* To assign the values to template variables */

            $customerDetails = array();
            $customerDetails['name'] = 'John Doe';
            $customerDetails['email'] = 'test@example.com';



            $objectManager->get('VendorNameCustomModuleHelperEmailreport')->sendEmailReport(
            $customEmailPath,
            $senderInfo,
            $receiverInfo,
            $customerDetails = []
            );






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jul 13 '17 at 4:00

























            answered Jul 12 '17 at 10:19









            HarithaHaritha

            386111




            386111












            • what should we configure here----$customEmailPath = 'section_id/group_id/field_id';

              – Raghu
              Jul 12 '17 at 10:36











            • For instance if we need the email template format of new sales order email give 'sales_email/order/template' . This field can be identified from /vendor/magento/module-sales/etc/adminhtml/system.xml

              – Haritha
              Jul 12 '17 at 10:43











            • we have given the transactional email ID there directly

              – Raghu
              Jul 12 '17 at 10:47











            • but we are getting this error Fatal error: Uncaught Error: Call to protected method NamespaceModulenameHelperEmailreport::sendEmailReport() from context '' in customtest.php:33 Stack trace: #0 main thrown in customtest.php on line 33

              – Raghu
              Jul 12 '17 at 10:47












            • Please check the updated code.

              – Haritha
              Jul 12 '17 at 11:57

















            • what should we configure here----$customEmailPath = 'section_id/group_id/field_id';

              – Raghu
              Jul 12 '17 at 10:36











            • For instance if we need the email template format of new sales order email give 'sales_email/order/template' . This field can be identified from /vendor/magento/module-sales/etc/adminhtml/system.xml

              – Haritha
              Jul 12 '17 at 10:43











            • we have given the transactional email ID there directly

              – Raghu
              Jul 12 '17 at 10:47











            • but we are getting this error Fatal error: Uncaught Error: Call to protected method NamespaceModulenameHelperEmailreport::sendEmailReport() from context '' in customtest.php:33 Stack trace: #0 main thrown in customtest.php on line 33

              – Raghu
              Jul 12 '17 at 10:47












            • Please check the updated code.

              – Haritha
              Jul 12 '17 at 11:57
















            what should we configure here----$customEmailPath = 'section_id/group_id/field_id';

            – Raghu
            Jul 12 '17 at 10:36





            what should we configure here----$customEmailPath = 'section_id/group_id/field_id';

            – Raghu
            Jul 12 '17 at 10:36













            For instance if we need the email template format of new sales order email give 'sales_email/order/template' . This field can be identified from /vendor/magento/module-sales/etc/adminhtml/system.xml

            – Haritha
            Jul 12 '17 at 10:43





            For instance if we need the email template format of new sales order email give 'sales_email/order/template' . This field can be identified from /vendor/magento/module-sales/etc/adminhtml/system.xml

            – Haritha
            Jul 12 '17 at 10:43













            we have given the transactional email ID there directly

            – Raghu
            Jul 12 '17 at 10:47





            we have given the transactional email ID there directly

            – Raghu
            Jul 12 '17 at 10:47













            but we are getting this error Fatal error: Uncaught Error: Call to protected method NamespaceModulenameHelperEmailreport::sendEmailReport() from context '' in customtest.php:33 Stack trace: #0 main thrown in customtest.php on line 33

            – Raghu
            Jul 12 '17 at 10:47






            but we are getting this error Fatal error: Uncaught Error: Call to protected method NamespaceModulenameHelperEmailreport::sendEmailReport() from context '' in customtest.php:33 Stack trace: #0 main thrown in customtest.php on line 33

            – Raghu
            Jul 12 '17 at 10:47














            Please check the updated code.

            – Haritha
            Jul 12 '17 at 11:57





            Please check the updated code.

            – Haritha
            Jul 12 '17 at 11:57













            0














            I have created above two mentioned file. I have run file on root. I am getting null values in email template as below image.
            enter image description here





            share








            New contributor




            Dinesh Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.
























              0














              I have created above two mentioned file. I have run file on root. I am getting null values in email template as below image.
              enter image description here





              share








              New contributor




              Dinesh Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






















                0












                0








                0







                I have created above two mentioned file. I have run file on root. I am getting null values in email template as below image.
                enter image description here





                share








                New contributor




                Dinesh Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.










                I have created above two mentioned file. I have run file on root. I am getting null values in email template as below image.
                enter image description here






                share








                New contributor




                Dinesh Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.








                share


                share






                New contributor




                Dinesh Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered 7 mins ago









                Dinesh RajputDinesh Rajput

                1




                1




                New contributor




                Dinesh Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                Dinesh Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                Dinesh Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f183281%2fsend-transactional-email-from-root-folder-magento-2%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

                    How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2

                    Nissan Patrol Зміст Перше покоління — 4W60 (1951-1960) | Друге покоління — 60 series (1960-1980) | Третє покоління (1980–2002) | Четверте покоління — Y60 (1987–1998) | П'яте покоління — Y61 (1997–2013) | Шосте покоління — Y62 (2010- ) | Посилання | Зноски | Навігаційне менюОфіційний український сайтТест-драйв Nissan Patrol 2010 7-го поколінняNissan PatrolКак мы тестировали Nissan Patrol 2016рвиправивши або дописавши її