Magento Commerce: How To Fix “Order confirmation email not sent”
Articles, Magento Commerce — By ScreencastWorld on March 8, 2010 at 08:18A question that is often asked in the Magento Forums relates to the “Order confirmation email not sent” message you see on the orders page.
Some may see this as a bug, but it’s not. It is by design, and supposed to work like this. Unfortunately the documentation isn’t clear which I think is the real bug here. If you use PayPal Standard, Google Checkout, or any Payment Gateway that redirects customers from your site to the payment gateway’s site you’ll get the “Order confirmation email not sent”.
The following is taken from 1.3.2.4 code so things may be different in earlier or later revisions.
The messages “Order confirmation email not sent” comes from the following code which checks to see if Magento previously sent the confirmation email. If it did, display “Order confirmation email sent”, otherwise display “Order confirmation email not sent”:
app/design/adminhtml/default/default/template/sales/order/view/info.phtml
<?php if ($_order->getEmailSent()):
$_email=$this->__('Order confirmation email sent');
else:
$_email=$this->__('Order confirmation email not sent');
endif;?>
Assuming you’re using the one-page checkout, the problem stems from the following piece of code:
app/code/core/Mage/Checkout/Model/Type/Onepage.php
/**
* a flag to set that there will be redirect to third party after confirmation
* eg: paypal standard ipn
*/
$redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
if(!$redirectUrl){
$order->setEmailSent(true);
}
(...snip...)
/**
* we only want to send to customer about new order when there is no redirect to third party
*/
if(!$redirectUrl){
$order->sendNewOrderEmail();
}
Note that the email flag is only sent when we DO NOT use an external/redirected payment system. Magento assumes that the confirmation email will be sent by the redirected payment gateway – PayPal, GoogleCheckout, etc. And this is true. Once you understand this it tends to make sense. Some store owners prefer to send their own confirmation emails as well. There’s nothing wrong with that and it does make a lot of sense.
So if you want to change the “Order confirmation email not sent” to “Order confirmation sent” change:
if(!$redirectUrl){
$order->setEmailSent(true);
}
- to -
// if(!$redirectUrl){
$order->setEmailSent(true);
// }
Or you can just remove the NOT (!) from the IF statement so if we are redirecting, send the emails and set the flag:
if($redirectUrl){
$order->setEmailSent(true);
}
Both methods achieve the same results.
The other potential workaround is to edit core/Mage/Paypal/controllers and add a call to ’setEmailSent(true)’. So change the following from:
public function redirectAction()
{
$session = Mage::getSingleton('checkout/session');
$session->setPaypalStandardQuoteId($session->getQuoteId());
$order = Mage::getModel('sales/order');
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
$order->sendNewOrderEmail();
$order->save();
$this->getResponse()->setBody($this->getLayout()->createBlock('paypal/standard_redirect')->toHtml());
$session->unsQuoteId();
}
- to -
public function redirectAction()
{
$session = Mage::getSingleton('checkout/session');
$session->setPaypalStandardQuoteId($session->getQuoteId());
$order = Mage::getModel('sales/order');
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
$order->sendNewOrderEmail();
$order->setEmailSent(true);
$order->save();
$this->getResponse()->setBody($this->getLayout()->createBlock('paypal/standard_redirect')->toHtml());
$session->unsQuoteId();
}
The latter method is a more global change so will work for any checkout method using PayPal, not just the single checkout page.
Remember to backup the files before you edit them, just in case things go wrong
Let me know if you found this useful.
Related posts:
- Magento Commerce 1.4: How To Fix ‘Unable to submit your request. Please, try again later’ on the Contact Us form
- Magento Developer Tip: How to Read and Write to the Database
- Magento Commerce Community Edition 1.4.1.0 is Released
- How To Fix: Magento-Connect Downloader Manager lists no packages
- Magento Commerce: Fixing “Exception printing is disabled by default for security reasons”


Tweet This
Digg This
Save to delicious
Stumble it





