以编程方式发送时,Magento新发货邮件空白

I have 2 servers running magento, one is the dev server and one is live.

I am sending shipment emails programatically after adding tracking information from an external source.

The email works fine using the code below on the dev server but the body of the email is blank on the live server even though the subject line is correct. When I send the email using the interface from the admin side, it works fine on the live server and the proper email goes through.

Any ideas why this might be happening ? Thank you

Here is the code

$shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentId);

if(!$shipment->getEmailSent())
{               
    $shipment->sendEmail();
    $shipment->setEmailSent(true);
    $shipment->save();                          
}

EDIT:

Upon viewing the exception.log file I found that the reason is

exception 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent

This could be due to retrieving the tracking info by sending a POST request to an API. What could I do to resolve the headers issue ?

Hopefully this helps anyone facing a similar problem. The issue was that I was outputting some text before calling the email sending block which was causing the error of headers not being sent.

I removed the text and it worked fine.