Magento is not sending emails when you click the Send Email
button in admin on Sales>order
.
Please Help.
All other mail are send. but this one is not working.
like order,order conform, invoice etc. all mail are sent
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityMagento is not sending emails when you click the Send Email
button in admin on Sales>order
.
Please Help.
All other mail are send. but this one is not working.
like order,order conform, invoice etc. all mail are sent
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.
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.
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();
}
}