Search code examples
phpmagentomagento2

How to send an Order Confirmation email from script


When I try sending an email from the root script in Magento I get the below error:

Fatal error:  Uncaught exception 'BadMethodCallException' with message 'Missing required argument $debugHintsPath of Magento\Developer\Model\TemplateEngine\Plugin\DebugHints.' in
/var/www/html/2x/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:45
Stack trace:
0 /var/www/html/2x/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(82):
Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments('Magento\\Develop...', Array, Array)
1 /var/www/html/2x/vendor/magento/framework/ObjectManager/ObjectManager.php(71):
Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\\Develop...')
2 /var/www/html/2x/vendor/magento/framework/Interception/PluginList/PluginList.php(234):
Magento\Framework\ObjectManager\ObjectManager->get('Magento\\Develop...')
3 /var/www/html/2x/vendor/magento/framework/Interception/Interceptor.php(149):
Magento\Framework\Interception\PluginList\PluginList->getPlugin('Magento\\Framewo...', 'debug_hints')
4 /var/www/html/2x/var/generati in /var/www/html/2x/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php
on line 45

Below is the code which I have used:

$orderid = '000000003';
$order = $obj->create('Magento\Sales\Model\Order')->loadByIncrementId($orderid);
// print_r($order->getData());

$obj->create('Magento\Sales\Model\Order\Email\Sender\OrderSender')->send($order,true);

Solution

  • try using

    $orderid = '000000003';
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderid);
    $objectManager->create('Magento\Sales\Model\OrderNotifier')->notify($order);