How to send email programmatically and display success message in magento 2












1















I am new to this magento. I want to send a email and display a success message in magento2. Anyone please give me a solution for sending a mail programmatically.










share|improve this question























  • You want so send mail from a custom form in front end or in backend?

    – Nero Phung
    Nov 25 '17 at 8:42
















1















I am new to this magento. I want to send a email and display a success message in magento2. Anyone please give me a solution for sending a mail programmatically.










share|improve this question























  • You want so send mail from a custom form in front end or in backend?

    – Nero Phung
    Nov 25 '17 at 8:42














1












1








1








I am new to this magento. I want to send a email and display a success message in magento2. Anyone please give me a solution for sending a mail programmatically.










share|improve this question














I am new to this magento. I want to send a email and display a success message in magento2. Anyone please give me a solution for sending a mail programmatically.







magento2.2 php-7






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '17 at 8:33









shineshine

113




113













  • You want so send mail from a custom form in front end or in backend?

    – Nero Phung
    Nov 25 '17 at 8:42



















  • You want so send mail from a custom form in front end or in backend?

    – Nero Phung
    Nov 25 '17 at 8:42

















You want so send mail from a custom form in front end or in backend?

– Nero Phung
Nov 25 '17 at 8:42





You want so send mail from a custom form in front end or in backend?

– Nero Phung
Nov 25 '17 at 8:42










3 Answers
3






active

oldest

votes


















1














Create your controller



<?php

namespace VendorModuleControllerIndex;

use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkControllerResultFactory;

class Index extends MagentoFrameworkAppActionAction
{

public function __construct(
MagentoFrameworkAppActionContext $context,
TransportBuilder $transportBuilder,
array $data = )
{
$this->transportBuilder = $transportBuilder;
return parent::__construct($context,$data);
}

public function execute()
{
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

try{
$post = $this->getRequest()->getPostValue();
$senderEmail = "sender_address@example.com";
$senderName = "Sender Name";
$recipientEmail = "receivers_address@example.com";

$identifier = 1; // Enter your email template identifier here

$requestData = array();

if($post['fname']){
$requestData['fname'] = $post['fname'];
}
if($post['address']){
$requestData['address'] = $post['address'];
}
if($post['city']){
$requestData['city'] = $post['city'];
}
if($post['state']){
$requestData['state'] = $post['state'];
}
// You can add more data as given above

$postObject = new MagentoFrameworkDataObject();
$postObject->setData($requestData);

$transport = $this->transportBuilder
->setTemplateIdentifier($identifier)
->setTemplateOptions(['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => MagentoStoreModelStore::DEFAULT_STORE_ID])
->setTemplateVars(['data' => $postObject])
->setFrom(['name' => $senderName,'email' => $senderEmail])
->addTo([$recipientEmail])
->getTransport();
$transport->sendMessage();

$this->messageManager->addSuccess(__('Email has been sent successfully.'));
$resultRedirect->setUrl($this->_redirect->getRefererUrl());
return $resultRedirect;
}catch(Exception $e){
$this->messageManager->addError(__('Something went wrong. Please try again later.'));
$resultRedirect->setUrl($this->_redirect->getRefererUrl());
return $resultRedirect;
}

}
}


Add below variables in your email template.



{{depend data.fname}}
{{trans "First Name: %fname" fname=$data.fname}}<br/>
{{/depend}}

{{depend data.address}}
{{trans "Address: %address" address=$data.address}}<br/>
{{/depend}}

{{depend data.city}}
{{trans "City: %city" city=$data.city}}<br/>
{{/depend}}

{{depend data.state}}
{{trans "State: %state" state=$data.state}}<br/>
{{/depend}}



Note: Put the action of your form to above controller.







share|improve this answer































    0














    simple sending email for objManager



        $objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
    $transport = $objectManager->create('MagentoFrameworkMailTemplateTransportBuilder');
    $templateVars = [
    'message' => $str_order,
    'order_no' => $str_order_no,
    'order_status' => $str_order_status,
    'order_day' => $str_order_day,
    'order_email' => $str_order_email,
    'order_product' => $str_order_product,
    'order_sku' => $str_order_sku,
    'order_namep' => $str_order_namep,
    'order_qty' => $str_order_qty,
    'order_paym' => $str_order_paym,
    'order_grand' => $str_order_grand
    ];

    $data = $transport
    ->setTemplateIdentifier(6)//get temptate id in your create in backend to use variable in backend you should use this tpye format etc . {{var message}} for message {{var order_no}} for order id
    ->setTemplateOptions(['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => 1])
    ->setTemplateVars($templateVars)
    ->setFrom(['name' => 'automate_order_notification','email' => 'magento_back@pa-phone.com'])
    ->addTo(['email_youwant_tosend@outlook.com','email_youwant_tosend@outlook.com'])
    ->getTransport();
    $data->sendMessage();





    share|improve this answer































      0














      I have shared a link for step by step guide to sending a custom mail from Magento 2 using a module.



      Magento 2 Uses MagentoFrameworkMailTemplateTransportBuilder class for send custom email.



      You need to create a simple module and set email_tempaltes.xml file for defining your transaction mail templates.



      You can send mail from Adminhtml or Frontend Scope area.






      share|improve this answer

























        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%2f203191%2fhow-to-send-email-programmatically-and-display-success-message-in-magento-2%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        Create your controller



        <?php

        namespace VendorModuleControllerIndex;

        use MagentoFrameworkMailTemplateTransportBuilder;
        use MagentoFrameworkControllerResultFactory;

        class Index extends MagentoFrameworkAppActionAction
        {

        public function __construct(
        MagentoFrameworkAppActionContext $context,
        TransportBuilder $transportBuilder,
        array $data = )
        {
        $this->transportBuilder = $transportBuilder;
        return parent::__construct($context,$data);
        }

        public function execute()
        {
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

        try{
        $post = $this->getRequest()->getPostValue();
        $senderEmail = "sender_address@example.com";
        $senderName = "Sender Name";
        $recipientEmail = "receivers_address@example.com";

        $identifier = 1; // Enter your email template identifier here

        $requestData = array();

        if($post['fname']){
        $requestData['fname'] = $post['fname'];
        }
        if($post['address']){
        $requestData['address'] = $post['address'];
        }
        if($post['city']){
        $requestData['city'] = $post['city'];
        }
        if($post['state']){
        $requestData['state'] = $post['state'];
        }
        // You can add more data as given above

        $postObject = new MagentoFrameworkDataObject();
        $postObject->setData($requestData);

        $transport = $this->transportBuilder
        ->setTemplateIdentifier($identifier)
        ->setTemplateOptions(['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => MagentoStoreModelStore::DEFAULT_STORE_ID])
        ->setTemplateVars(['data' => $postObject])
        ->setFrom(['name' => $senderName,'email' => $senderEmail])
        ->addTo([$recipientEmail])
        ->getTransport();
        $transport->sendMessage();

        $this->messageManager->addSuccess(__('Email has been sent successfully.'));
        $resultRedirect->setUrl($this->_redirect->getRefererUrl());
        return $resultRedirect;
        }catch(Exception $e){
        $this->messageManager->addError(__('Something went wrong. Please try again later.'));
        $resultRedirect->setUrl($this->_redirect->getRefererUrl());
        return $resultRedirect;
        }

        }
        }


        Add below variables in your email template.



        {{depend data.fname}}
        {{trans "First Name: %fname" fname=$data.fname}}<br/>
        {{/depend}}

        {{depend data.address}}
        {{trans "Address: %address" address=$data.address}}<br/>
        {{/depend}}

        {{depend data.city}}
        {{trans "City: %city" city=$data.city}}<br/>
        {{/depend}}

        {{depend data.state}}
        {{trans "State: %state" state=$data.state}}<br/>
        {{/depend}}



        Note: Put the action of your form to above controller.







        share|improve this answer




























          1














          Create your controller



          <?php

          namespace VendorModuleControllerIndex;

          use MagentoFrameworkMailTemplateTransportBuilder;
          use MagentoFrameworkControllerResultFactory;

          class Index extends MagentoFrameworkAppActionAction
          {

          public function __construct(
          MagentoFrameworkAppActionContext $context,
          TransportBuilder $transportBuilder,
          array $data = )
          {
          $this->transportBuilder = $transportBuilder;
          return parent::__construct($context,$data);
          }

          public function execute()
          {
          $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

          try{
          $post = $this->getRequest()->getPostValue();
          $senderEmail = "sender_address@example.com";
          $senderName = "Sender Name";
          $recipientEmail = "receivers_address@example.com";

          $identifier = 1; // Enter your email template identifier here

          $requestData = array();

          if($post['fname']){
          $requestData['fname'] = $post['fname'];
          }
          if($post['address']){
          $requestData['address'] = $post['address'];
          }
          if($post['city']){
          $requestData['city'] = $post['city'];
          }
          if($post['state']){
          $requestData['state'] = $post['state'];
          }
          // You can add more data as given above

          $postObject = new MagentoFrameworkDataObject();
          $postObject->setData($requestData);

          $transport = $this->transportBuilder
          ->setTemplateIdentifier($identifier)
          ->setTemplateOptions(['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => MagentoStoreModelStore::DEFAULT_STORE_ID])
          ->setTemplateVars(['data' => $postObject])
          ->setFrom(['name' => $senderName,'email' => $senderEmail])
          ->addTo([$recipientEmail])
          ->getTransport();
          $transport->sendMessage();

          $this->messageManager->addSuccess(__('Email has been sent successfully.'));
          $resultRedirect->setUrl($this->_redirect->getRefererUrl());
          return $resultRedirect;
          }catch(Exception $e){
          $this->messageManager->addError(__('Something went wrong. Please try again later.'));
          $resultRedirect->setUrl($this->_redirect->getRefererUrl());
          return $resultRedirect;
          }

          }
          }


          Add below variables in your email template.



          {{depend data.fname}}
          {{trans "First Name: %fname" fname=$data.fname}}<br/>
          {{/depend}}

          {{depend data.address}}
          {{trans "Address: %address" address=$data.address}}<br/>
          {{/depend}}

          {{depend data.city}}
          {{trans "City: %city" city=$data.city}}<br/>
          {{/depend}}

          {{depend data.state}}
          {{trans "State: %state" state=$data.state}}<br/>
          {{/depend}}



          Note: Put the action of your form to above controller.







          share|improve this answer


























            1












            1








            1







            Create your controller



            <?php

            namespace VendorModuleControllerIndex;

            use MagentoFrameworkMailTemplateTransportBuilder;
            use MagentoFrameworkControllerResultFactory;

            class Index extends MagentoFrameworkAppActionAction
            {

            public function __construct(
            MagentoFrameworkAppActionContext $context,
            TransportBuilder $transportBuilder,
            array $data = )
            {
            $this->transportBuilder = $transportBuilder;
            return parent::__construct($context,$data);
            }

            public function execute()
            {
            $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

            try{
            $post = $this->getRequest()->getPostValue();
            $senderEmail = "sender_address@example.com";
            $senderName = "Sender Name";
            $recipientEmail = "receivers_address@example.com";

            $identifier = 1; // Enter your email template identifier here

            $requestData = array();

            if($post['fname']){
            $requestData['fname'] = $post['fname'];
            }
            if($post['address']){
            $requestData['address'] = $post['address'];
            }
            if($post['city']){
            $requestData['city'] = $post['city'];
            }
            if($post['state']){
            $requestData['state'] = $post['state'];
            }
            // You can add more data as given above

            $postObject = new MagentoFrameworkDataObject();
            $postObject->setData($requestData);

            $transport = $this->transportBuilder
            ->setTemplateIdentifier($identifier)
            ->setTemplateOptions(['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => MagentoStoreModelStore::DEFAULT_STORE_ID])
            ->setTemplateVars(['data' => $postObject])
            ->setFrom(['name' => $senderName,'email' => $senderEmail])
            ->addTo([$recipientEmail])
            ->getTransport();
            $transport->sendMessage();

            $this->messageManager->addSuccess(__('Email has been sent successfully.'));
            $resultRedirect->setUrl($this->_redirect->getRefererUrl());
            return $resultRedirect;
            }catch(Exception $e){
            $this->messageManager->addError(__('Something went wrong. Please try again later.'));
            $resultRedirect->setUrl($this->_redirect->getRefererUrl());
            return $resultRedirect;
            }

            }
            }


            Add below variables in your email template.



            {{depend data.fname}}
            {{trans "First Name: %fname" fname=$data.fname}}<br/>
            {{/depend}}

            {{depend data.address}}
            {{trans "Address: %address" address=$data.address}}<br/>
            {{/depend}}

            {{depend data.city}}
            {{trans "City: %city" city=$data.city}}<br/>
            {{/depend}}

            {{depend data.state}}
            {{trans "State: %state" state=$data.state}}<br/>
            {{/depend}}



            Note: Put the action of your form to above controller.







            share|improve this answer













            Create your controller



            <?php

            namespace VendorModuleControllerIndex;

            use MagentoFrameworkMailTemplateTransportBuilder;
            use MagentoFrameworkControllerResultFactory;

            class Index extends MagentoFrameworkAppActionAction
            {

            public function __construct(
            MagentoFrameworkAppActionContext $context,
            TransportBuilder $transportBuilder,
            array $data = )
            {
            $this->transportBuilder = $transportBuilder;
            return parent::__construct($context,$data);
            }

            public function execute()
            {
            $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

            try{
            $post = $this->getRequest()->getPostValue();
            $senderEmail = "sender_address@example.com";
            $senderName = "Sender Name";
            $recipientEmail = "receivers_address@example.com";

            $identifier = 1; // Enter your email template identifier here

            $requestData = array();

            if($post['fname']){
            $requestData['fname'] = $post['fname'];
            }
            if($post['address']){
            $requestData['address'] = $post['address'];
            }
            if($post['city']){
            $requestData['city'] = $post['city'];
            }
            if($post['state']){
            $requestData['state'] = $post['state'];
            }
            // You can add more data as given above

            $postObject = new MagentoFrameworkDataObject();
            $postObject->setData($requestData);

            $transport = $this->transportBuilder
            ->setTemplateIdentifier($identifier)
            ->setTemplateOptions(['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => MagentoStoreModelStore::DEFAULT_STORE_ID])
            ->setTemplateVars(['data' => $postObject])
            ->setFrom(['name' => $senderName,'email' => $senderEmail])
            ->addTo([$recipientEmail])
            ->getTransport();
            $transport->sendMessage();

            $this->messageManager->addSuccess(__('Email has been sent successfully.'));
            $resultRedirect->setUrl($this->_redirect->getRefererUrl());
            return $resultRedirect;
            }catch(Exception $e){
            $this->messageManager->addError(__('Something went wrong. Please try again later.'));
            $resultRedirect->setUrl($this->_redirect->getRefererUrl());
            return $resultRedirect;
            }

            }
            }


            Add below variables in your email template.



            {{depend data.fname}}
            {{trans "First Name: %fname" fname=$data.fname}}<br/>
            {{/depend}}

            {{depend data.address}}
            {{trans "Address: %address" address=$data.address}}<br/>
            {{/depend}}

            {{depend data.city}}
            {{trans "City: %city" city=$data.city}}<br/>
            {{/depend}}

            {{depend data.state}}
            {{trans "State: %state" state=$data.state}}<br/>
            {{/depend}}



            Note: Put the action of your form to above controller.








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 25 '17 at 9:32









            Dinesh YadavDinesh Yadav

            3,8401937




            3,8401937

























                0














                simple sending email for objManager



                    $objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
                $transport = $objectManager->create('MagentoFrameworkMailTemplateTransportBuilder');
                $templateVars = [
                'message' => $str_order,
                'order_no' => $str_order_no,
                'order_status' => $str_order_status,
                'order_day' => $str_order_day,
                'order_email' => $str_order_email,
                'order_product' => $str_order_product,
                'order_sku' => $str_order_sku,
                'order_namep' => $str_order_namep,
                'order_qty' => $str_order_qty,
                'order_paym' => $str_order_paym,
                'order_grand' => $str_order_grand
                ];

                $data = $transport
                ->setTemplateIdentifier(6)//get temptate id in your create in backend to use variable in backend you should use this tpye format etc . {{var message}} for message {{var order_no}} for order id
                ->setTemplateOptions(['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => 1])
                ->setTemplateVars($templateVars)
                ->setFrom(['name' => 'automate_order_notification','email' => 'magento_back@pa-phone.com'])
                ->addTo(['email_youwant_tosend@outlook.com','email_youwant_tosend@outlook.com'])
                ->getTransport();
                $data->sendMessage();





                share|improve this answer




























                  0














                  simple sending email for objManager



                      $objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
                  $transport = $objectManager->create('MagentoFrameworkMailTemplateTransportBuilder');
                  $templateVars = [
                  'message' => $str_order,
                  'order_no' => $str_order_no,
                  'order_status' => $str_order_status,
                  'order_day' => $str_order_day,
                  'order_email' => $str_order_email,
                  'order_product' => $str_order_product,
                  'order_sku' => $str_order_sku,
                  'order_namep' => $str_order_namep,
                  'order_qty' => $str_order_qty,
                  'order_paym' => $str_order_paym,
                  'order_grand' => $str_order_grand
                  ];

                  $data = $transport
                  ->setTemplateIdentifier(6)//get temptate id in your create in backend to use variable in backend you should use this tpye format etc . {{var message}} for message {{var order_no}} for order id
                  ->setTemplateOptions(['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => 1])
                  ->setTemplateVars($templateVars)
                  ->setFrom(['name' => 'automate_order_notification','email' => 'magento_back@pa-phone.com'])
                  ->addTo(['email_youwant_tosend@outlook.com','email_youwant_tosend@outlook.com'])
                  ->getTransport();
                  $data->sendMessage();





                  share|improve this answer


























                    0












                    0








                    0







                    simple sending email for objManager



                        $objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
                    $transport = $objectManager->create('MagentoFrameworkMailTemplateTransportBuilder');
                    $templateVars = [
                    'message' => $str_order,
                    'order_no' => $str_order_no,
                    'order_status' => $str_order_status,
                    'order_day' => $str_order_day,
                    'order_email' => $str_order_email,
                    'order_product' => $str_order_product,
                    'order_sku' => $str_order_sku,
                    'order_namep' => $str_order_namep,
                    'order_qty' => $str_order_qty,
                    'order_paym' => $str_order_paym,
                    'order_grand' => $str_order_grand
                    ];

                    $data = $transport
                    ->setTemplateIdentifier(6)//get temptate id in your create in backend to use variable in backend you should use this tpye format etc . {{var message}} for message {{var order_no}} for order id
                    ->setTemplateOptions(['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => 1])
                    ->setTemplateVars($templateVars)
                    ->setFrom(['name' => 'automate_order_notification','email' => 'magento_back@pa-phone.com'])
                    ->addTo(['email_youwant_tosend@outlook.com','email_youwant_tosend@outlook.com'])
                    ->getTransport();
                    $data->sendMessage();





                    share|improve this answer













                    simple sending email for objManager



                        $objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
                    $transport = $objectManager->create('MagentoFrameworkMailTemplateTransportBuilder');
                    $templateVars = [
                    'message' => $str_order,
                    'order_no' => $str_order_no,
                    'order_status' => $str_order_status,
                    'order_day' => $str_order_day,
                    'order_email' => $str_order_email,
                    'order_product' => $str_order_product,
                    'order_sku' => $str_order_sku,
                    'order_namep' => $str_order_namep,
                    'order_qty' => $str_order_qty,
                    'order_paym' => $str_order_paym,
                    'order_grand' => $str_order_grand
                    ];

                    $data = $transport
                    ->setTemplateIdentifier(6)//get temptate id in your create in backend to use variable in backend you should use this tpye format etc . {{var message}} for message {{var order_no}} for order id
                    ->setTemplateOptions(['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => 1])
                    ->setTemplateVars($templateVars)
                    ->setFrom(['name' => 'automate_order_notification','email' => 'magento_back@pa-phone.com'])
                    ->addTo(['email_youwant_tosend@outlook.com','email_youwant_tosend@outlook.com'])
                    ->getTransport();
                    $data->sendMessage();






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 14 '18 at 7:28









                    May NoppadolMay Noppadol

                    112




                    112























                        0














                        I have shared a link for step by step guide to sending a custom mail from Magento 2 using a module.



                        Magento 2 Uses MagentoFrameworkMailTemplateTransportBuilder class for send custom email.



                        You need to create a simple module and set email_tempaltes.xml file for defining your transaction mail templates.



                        You can send mail from Adminhtml or Frontend Scope area.






                        share|improve this answer






























                          0














                          I have shared a link for step by step guide to sending a custom mail from Magento 2 using a module.



                          Magento 2 Uses MagentoFrameworkMailTemplateTransportBuilder class for send custom email.



                          You need to create a simple module and set email_tempaltes.xml file for defining your transaction mail templates.



                          You can send mail from Adminhtml or Frontend Scope area.






                          share|improve this answer




























                            0












                            0








                            0







                            I have shared a link for step by step guide to sending a custom mail from Magento 2 using a module.



                            Magento 2 Uses MagentoFrameworkMailTemplateTransportBuilder class for send custom email.



                            You need to create a simple module and set email_tempaltes.xml file for defining your transaction mail templates.



                            You can send mail from Adminhtml or Frontend Scope area.






                            share|improve this answer















                            I have shared a link for step by step guide to sending a custom mail from Magento 2 using a module.



                            Magento 2 Uses MagentoFrameworkMailTemplateTransportBuilder class for send custom email.



                            You need to create a simple module and set email_tempaltes.xml file for defining your transaction mail templates.



                            You can send mail from Adminhtml or Frontend Scope area.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 4 mins ago

























                            answered Dec 25 '18 at 6:35









                            Rakesh JesadiyaRakesh Jesadiya

                            28.8k1571119




                            28.8k1571119






























                                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%2f203191%2fhow-to-send-email-programmatically-and-display-success-message-in-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

                                What other Star Trek series did the main TNG cast show up in?

                                Berlina muro

                                Berlina aerponto