Send transactional email from root folder magento 2Magento2 get email templates dropdown in stores...

Would a high gravity rocky planet be guaranteed to have an atmosphere?

Flow chart document symbol

How to pronounce the slash sign

A Rare Riley Riddle

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

Customer Requests (Sometimes) Drive Me Bonkers!

What is the difference between "behavior" and "behaviour"?

Replace character with another only if repeated and not part of a word

What does 算不上 mean in 算不上太美好的日子?

Go Pregnant or Go Home

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

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

Large drywall patch supports

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

Is HostGator storing my password in plaintext?

Is there a good way to store credentials outside of a password manager?

Was Spock the First Vulcan in Starfleet?

Escape a backup date in a file name

How can I quit an app using Terminal?

Is exact Kanji stroke length important?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

Valid Badminton Score?

Would this custom Sorcerer variant that can only learn any verbal-component-only spell be unbalanced?

Is a stroke of luck acceptable after a series of unfavorable events?



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|improve this answer








          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|improve this answer








            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|improve this answer








              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|improve this answer








                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|improve this answer








                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|improve this answer



                share|improve this answer






                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 16 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

                    “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                    How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                    夢乃愛華...