All posts tagged email


There is a bug in Paypal Standard for Magento, when a customer has finished the order process and validate his payment in Paypal, the customer doesn’t receive any email including his invoice. He receives only a confirmation payment of Paypal and a message after the process to tell him that the order is going to be proceeded.

To resolve this problem, two possibilities:

  • Overload the class in your own module : Mage_Paypal_Model_Standard (app/code/core/Mage/Paypal/Model/) at the line 418 after $invoice->register()->pay();, add the following line: $invoice->sendEmail();
  • Create an event with the help of a class Observer.php which trigger after the event sales_order_invoice_pay, which in Paypal standard start at line 418, after the treatment $invoice->register()->pay(). To do it, you have to create a module (there is lots of tutorials on Google to know how to do it) with the following files (replace Name by the name of your module):
    • /app/code/local/Name/Sales/etc/config.xml
    • /app/code/local/Name/Sales/Model/Observer.php
    • /app/etc/modules/Name_All.xm
Here the content:
<?xml version="1.0" encoding="UTF-8"?>


 * Event sales_order_invoice_pay
require_once 'Mage/Sales/Model/Observer.php';
class Name_Sales_Model_Observer extends Mage_Sales_Model_Observer {
    public function sendInvoiceEmail($observer) {
            $invoice = $observer->getEvent ()->getInvoice ();
            switch ($invoice->getState ()) {
                case Mage_Sales_Model_Order_Invoice::STATE_PAID :
		try {
			// Save first time the invoice to get an id and send the invoice to the customer with the correct id
			$invoice->save ();
			Mage::log ('Email sent to the customer by the Name/sales/observer - Invoice number ' . $invoice->getIncrementId(), Zend_Log::DEBUG );
			$invoice->sendEmail ();
			$invoice->setEmailSent ( true );
			// Save a second time to save the EmailSent value
			$invoice->save ();
		} catch ( Exception $e ) {
			$session = Mage::getSingleton ( 'core/session' );
			$exception = new Exception ( Mage::helper('Sales')->__('Error during the email sending.'), 0 );
			$session->addException ( $exception, Mage::helper('Sales')->__('Error to send invoice email. Please, contact the website administrator.') );
        return $this;


<?xml version="1.0"?>

In Paypal Express, the interesting line is in the controller /app/code/core/Mage/Paypal/controllers/expressController.php, in the method updateorderAction(){} the code is near of $invoice->register()->capture(); add $invoice->sendEmail(); or use this observer (untested).

For more information about the events I invite you to visit the Magento website which make good explanation: Customizing Magento using Event-Observer Method