I want to send an email to customer after placing an order in Magento 2.

Please send/tell me how to extend the functionality in Magento 2


I have created my new module Roshan_Checkout inside app/code and in etc folder I created a event.xml file and call a method from there which is defined in my observer.

But, I'm not able to reach there in my observer and don't know how to extend the checkout functionality.

Would be greatful to you if you tell the step by step procedure to do the same. Thanks in advanced.

  • Please provide a code snippet of what you have tried so far. What is it you are stuck on, specifically? Have you tried looking at what Magento does? Oct 6, 2015 at 14:23
  • use sales_order_place_after event. Feb 22, 2017 at 4:32
  • check link,you will get your answer-> magento.stackexchange.com/a/208792/24878
    – akgola
    Jan 10, 2018 at 4:50

4 Answers 4


In order to use the observer, specify the folder frontend or adminhtml in etc folder and inside that use events.xml then call the observer. You can get the order details in observer using $observer->getOrderIds();.

  • Can you please provide the name of the event which the observer should listen?
    – Ervin
    Jan 12, 2017 at 19:49
  • 1
    @ErvinLlojku, "checkout_onepage_controller_success_action" is event name.
    – akgola
    Jan 10, 2018 at 4:58

If you want to observe ONLY the frontend for placing order then you can you the event checkout_onepage_controller_success_action in etc/frontend/events.xml

<event name="checkout_onepage_controller_success_action">
    <observer name="vendor_module_send_email" instance="Vendor\Module\Observer\SendEmail"  />

Note: This is not going to work if you have custom checkout extension which uses different controller name or you are redirecting customers to payment gateways pages. In that case you can observe sales_order_place_after in both frontend and adminhtml because this event is triggered from the Order model Magento\Sales\Model\Order in place() method.

For sending emails you can search in Google and find some tutorial for sending emails from controller and you just need to move the logic to helper and use it in the observer.


Use the event "checkout_onepage_controller_success_action" and in the observer use|inject transport builder class to send an email.


Use the event "sales_model_service_quote_submit_success" in the file Module/etc/frontend/events.xml with content :

<event name="sales_model_service_quote_submit_success">
    <observer name="sendNewEmail" instance="Compay\Module\Observer\QuoteSubmitSuccess" />

In function execute() you can get order detail :

public function execute(\Magento\Framework\Event\Observer $observer)
    /** @var \Magento\Sales\Model\Order $order */
    $order = $observer->getEvent()->getOrder();
    // code send email here

Then write your code for send email with order detail

Hope it helps !

Your Answer

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

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