Prabhu
Prabhu

Reputation: 1149

How to send email after successful checkout process?

In my store, I have created a custom module for one-step checkout process.

All the code works fine. But the order detail email is not sent to the customer after the checkout process. Here is the relevant part of my code.

$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();                          
$order = $service->getOrder();

//This one is the email send code

$order_mail = new Mage_Sales_Model_Order();
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order_mail->loadByIncrementId($incrementId);
$order_mail->sendNewOrderEmail();               

$this->_redirect('downloadable/customer/products/');

Upvotes: 4

Views: 3585

Answers (4)

nazim10
nazim10

Reputation: 129

Try this,

 < ?php
$order = new Mage_Sales_Model_Order();
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order->loadByIncrementId($incrementId);
try
{
$order->sendNewOrderEmail();
} catch (Exception $ex) {  }
?>

Save the above snippet as .phtml and upload it in app/code/core/Mage.

Now make an order in your site and check after successful checkout Email is sending or not.Hope your problem should solved now.

Upvotes: 0

user1638055
user1638055

Reputation: 492

Did you debug when it goes into sendNewOrderEmail? Maybe this helps to figure out where the problem is?

Regards

Upvotes: 0

MagePal Extensions
MagePal Extensions

Reputation: 17656

To send/resend an order email in magento

try {

    $incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
    $_order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
    $_order->sendNewOrderEmail();

    $this->_getSession()->addSuccess($this->__('The order email has been sent.'));

} catch (Exception $e) {
    $this->_getSession()->addError($this->__('Failed to send the order email.'));
    Mage::logException($e);
}

Upvotes: 4

Rachel Gallen
Rachel Gallen

Reputation: 28563

try putting it in a try catch to see what the error is like this

<?php
  $order_mail = new Mage_Sales_Model_Order();
  $incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
  $order_mail->loadByIncrementId($incrementId);
  try
  {
  $order_mail->sendNewOrderEmail();
  } catch (Exception $ex) {  }
 ?>

Upvotes: 1

Related Questions