3

Magento is not sending emails when you click the Send Email button in admin on Sales>order.

Eroor Image

Please Help.

All other mail are send. but this one is not working.

like order,order conform, invoice etc. all mail are sent

7
  • Any magento logs? Any php logs?
    – kuba_ceg
    Jun 19, 2014 at 9:41
  • no i check log not have any error in log. Jun 19, 2014 at 9:41
  • Did you check spambox? Check mail log for any errors on your's server. Other magento mails works?
    – kuba_ceg
    Jun 19, 2014 at 9:49
  • @kuba_ceg means when customer place order then the mail is send and yes i also check log files not have any errors and warning. Jun 19, 2014 at 9:50
  • There in the mail log is any sign of this message?
    – kuba_ceg
    Jun 19, 2014 at 10:24

3 Answers 3

9

In case you haven't figured this out or for future reference, Magento checks to see if the order email has already been sent or not and if it has, it returns out of the function without any error, thus pretending everything worked out.

Copy: app/code/core/Mage/Sales/Model/Order.php

Into: app/code/local/Mage/Sales/Model/Order.php

on line 1275 (Magento 1.9.0.1), comment out return $this;

if ($this->getEmailSent()) {
    //return $this;
}

This works and is tested on Magento 1.9.0.1, but it should also work for previous versions too.

3
  • I'm sure previous versions I've never had this problem. Why would Magento introduce it now?
    – Adam Moss
    Oct 28, 2014 at 11:52
  • 1
    This just saved me, why would this have appeared in 1.9.0.1 ?!
    – SR_Magento
    Jun 15, 2015 at 17:58
  • 1
    Why, Magento, why? Nov 13, 2015 at 16:01
4

The method Mage_Sales_Model_Order::sendNewOrderEmail checks whether the order email has been sent before. If this is the case, no email will be sent. This might be the desired behaviour for most calls to this method, but not for the call from controller handling the "Send email" functionality.

The "Send email" functionality corresponds to the method Mage_Adminhtml_Sales_OrderController::emailAction. This method initialises an order object based on the request parameter (the call to $this->_initOrder()), followed by a call to $order->sendNewOrderEmail(), which includes the check whether the order email has been sent before. Now this check can be disabled by prepending this call with $order->setEmailSent(false). After adding this line, the method should look as follows (Magento CE 1.9.0.1):

public function emailAction()
{
    if ($order = $this->_initOrder()) {
        try {
            //Start fix 'Send Email' button on Admin > Sales > Order > View page
            $order->setEmailSent(false); 
            //End fix 'Send Email' button on Admin > Sales > Order > View page
            $order->sendNewOrderEmail();
            $historyItem = Mage::getResourceModel('sales/order_status_history_collection')
                ->getUnnotifiedForInstance($order, Mage_Sales_Model_Order::HISTORY_ENTITY_NAME);
            if ($historyItem) {
                $historyItem->setIsCustomerNotified(1);
                $historyItem->save();
            }
            $this->_getSession()->addSuccess($this->__('The order email has been sent.'));
        } catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage());
        } catch (Exception $e) {
            $this->_getSession()->addError($this->__('Failed to send the order email.'));
            Mage::logException($e);
        }
    }
    $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
}

Put this method in an override of the original admin controller.

BTW It has been suggested earlier that it is also possible to disable the check whether the email has been sent before in the method Mage_Sales_Model_Order::sendNewOrderEmail itself. Whereas this also seems to work, this method is called from 13 different places, while the fix is only needed for one of them.

2
  • I have no problem sending mails over and over again from the backend? But I tested only in 1.8 Oct 1, 2014 at 14:52
  • we see this also on 1.9.0.1
    – snh_nl
    Feb 6, 2016 at 13:45
1

Dustin's solution will work and is easy to implement but a better solution would be to override the controller.

require_once(Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'Sales' . DS . 'OrderController.php');

class Jfunk_Fix_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController{
    //overide broken function that won't resend if sent before
    public function emailAction(){
        $id = $this->getRequest()->getParam('order_id');
        if ($order = Mage::getModel('sales/order')->load($id)) {
            $order->setEmailSent(0)->save();
        }
        parent::emailAction();
    }
}

Your Answer

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

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