While creating an invoice programmatically, how can I make the system email the invoice to the customer?

$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
    Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
$transactionSave = Mage::getModel('core/resource_transaction')

1 Answer 1


After $transactionSave->save();:

$history = $invoice->getOrder()->addStatusHistoryComment(
    'Programmatically created invoice', true
$invoice->sendEmail(true, '');

This will instruct Magento to email the invoice to the customer.

  • is the set status is necessary for sending the email? Apr 30, 2015 at 9:57
  • Yes, this is a Magento norm. If not included, the order will not be set to Processing (which it should be once invoiced).
    – Moose
    Apr 30, 2015 at 11:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.