Magento 2: How to Send Order Confirmation Email After Payment Success

Magento 2: How to Send Order Confirmation Email After Payment Success
May 21, 2020 591 view(s)
Magento 2: How to Send Order Confirmation Email After Payment Success

Normally, Default Magento 2 already send order confirmation emails to customers immediately after they placing orders. This comfirmation give the customers the patience to wait for the delivery after they have spent their money. It's very helpful for customers satisfaction and hence improving the customers experience of your store!

However, sometime, you want to send another email to customers after the success. So we should have some customization to allow to send this email.

To an email on successful order payment, we need to tie Magento 2 observer with an event of checkout_onepage_controller_success_action.
Create a simple method isEnable() using OrderIdentity.php to ensure that order confirmation email is not sent twice. 

Register event under events.xml using below code
Magezend\Sendemail\etc\frontend\events.xml

Once the event is registered, create Observer class in the following file:
Magezend\Sendemail\Observer\SendMailOnOrderSuccess.php

After adding observer code, an email will be sent to customers on successful order payment. To avoid order duplication Email, we need to create a plugin using the di.xml file.
Magezend\Sendemail\etc\di.xml

Create another file along with ‘di.xml’ that is OrderIdentityPlugin.php to remove duplication of email.
Magezend\Sendemail\Plugin\Sales\Order\Email\Container\ OrderIdentityPlugin.php

There you go!


Now you can send an extra email to your customers only after the payment is successful.

Thank you!