Magento automatically sends various emails for registration, order, refunds and many more. Generally, Magento auto sends an email once the order is placed but what if someone wants to send email after a successful payment completion from the third-party payment gateways in Magento 2? one of our client came up with the same requirement of sending an order confirmation email after successful order payment.
Unfortunately, Default Magento does not provide functionality of sending email after getting successful payment from third-party gateways, and to nail it, we have come up with custom code to send Email manually using observer.
To send email confirmation on successful order payment, we need to tie Magento 2 observer with an event of checkout_onepage_controller_success_action.
Here, we need to ensure that order confirmation email is not sent twice, So we need to create a simple method isEnable() using OrderIdentity.php.
First, we need to register event under events.xml using below code
[Package_Name]\[Module_Name]\etc\frontend\events.xml
Once event is registered, we need to create Observer class in following file.
[Package_Name]\[Module_Name]\Observer\SendMailOnOrderSuccess.php
[Package_Name]\[Module_Name]\etc\di.xml
And Lastly, you need to create another file along with ‘di.xml’ that is OrderIdentityPlugin.php to remove duplication of email.
[Package_Name]\[Module_Name]\Plugin\Sales\Order\Email\Container\ OrderIdentityPlugin.php
Note: To make use of above code or extension, you must disable the default Order Email from your Magento 2 store backend to enjoy the extension/above code functionality. Simply, navigate to Store -> Configuration -> Sales -> Sales email -> Order -> and set default Enabled option to “No” as shown below.Let me know if you face any issue using this code to send an order confirmation Email. Queries, suggestions and feedback are always welcomed through commenting. Happy Mailing!
Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…
MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…
In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…
Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…
The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…
Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…
View Comments
But admin email is also blocked when i disable email in config, any solution for this?
I have tried your solution, still m getting the email triggering twice one at checkout and another at payment success.
On Disable Default Email from the Admin Back end, It’s stop sending email at both checkout and on payment success.
Your Quick response will be appreciated as we are stuck with this to make the Site Live.
We have developed the free extension. You can try that one.
Hi,
I have not received the Order Confirmation Email After Successful Payment, i am using 2.4.2 Magento version
Only payu email i have received can you tell me what is the issue
COD & Bank transfer email working
We have developed the free extension. You can try that one.
Hi,
This is not working for magento2.3.5-p2.
Please suggest solution.
Thank you
Can you please specify what issue you are facing?
Hi, I use Magento ver. 2.3.5-p1 and it doesn't work for me too.
it gets right order on SendMailOnOrderSuccess.php line 52.
But email is not sending.
regular order confirmations are sending fine.
Is it necessary to disable default Order option to "No" under Sales Emails Section?
because mail is not working during online payment complete process .
Yes otherwise you will receive 2 email notifications.
So this can work mainly if you have only online payment methods enabled.
I dont want to stop Cash on delivery email when order placed. Is this code compatible with this?
Hello Support Team,
I am really thankful for this extension. it is working fine from fronend but it is not working from backend.
can you provide any solutions for backend.
Is there any way to do this without using the checkout_onepage_controller_success_action event? We are using it to do other important task
Regards!
No without that one it may not possible.
No issues if you use the same events for the other tasks, you can put above code with your that code, both should work normally.
Hi I have created above module as per your instruction.
I need instruction how & where i have to put this code.
Should i comment Default order Email ???
The [Package_Name][Module_Name]etcdi.xml code itself stops email duplication. So you don't need to comment anything.