Magento – Invoice emails are not being sent

invoicemagento-1.6paypal-express

I have Magento 1.6.0.0 and I use Paypal Express Checkout. The issue is that Invoice emails are not automatically sent. It says at the invoice details page:

the invoice email is not sent

Can someone tell me whats the issue here?

The Order confirmation emails are sent successfully and I think Paypal data is also getting captured via IPN (or by PDT) as I am getting "Payment Information" filled with data coming from paypal.

Let me know how to get this solved.

Thanks a lot.

Best Answer

config.xml

<global>
   <events>
        <sales_order_payment_pay>
            <observers>
                <some_module_node>
                    <class>Some_Module_Model_Observer</class>
                    <method>salesOrderPaymentPay</method>
                </some_module_node>
            </observers>
        </sales_order_payment_pay>
    </events>
</global>

Observer.php:

class Some_Module_Model_Observer
{
    public function salesOrderPaymentPay($observer)
    {
        /**
         * @var $invoice Mage_Sales_Model_Order_Invoice
         * @var $paymentMethod Mage_Payment_Model_Method_Abstract
         */
        $invoice       = $observer->getEvent()->getInvoice();
        $paymentMethod = $observer->getEvent()->getPayment()->getMethodInstance();
        if ($paymentMethod->getCode() == Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS && !$invoice->getEmailSent()) {
            $invoice->sendEmail(TRUE);
        }

    }
}