How can I test order emails specifying order ID without sending me the email but with a .php file that I call up in the browser?
2 Answers
Try below code and check.
- Create a new order in the backend of Magento 2.
- Go to the sales order view page and find the "Send Email" button.
- Click the "Send Email" button and wait for the email to be sent.
- Check the email address associated with the order to see if the email was received.
If you need to test the order email functionality using a PHP script, you can create a custom script in Magento 2 to send an order email programmatically. Here is an example of how to do this:
File name is testsendorder.php
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$order = $obj->create('Magento\Sales\Model\Order')->loadByIncrementId('100000XXX');
$orderSender = $obj->create('Magento\Sales\Model\Order\Email\Sender\OrderSender');
$orderSender->send($order);
echo 'Order email sent successfully.';
Replace '100000XXX'
with your actual order increment ID.
Now run script in broswer using that URL :- http://127.0.0.1/yourproject/pub/testsendorder.php
Let me know if any query.
THANKS.
I use this module by many years https://www.yireo.com/software/magento-extensions/emailtester2
It's not perfect because not all variables are passed but is good for common task.
With this module you can keep sending each email template in the locale you prefair