Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've managed to create an Observer to automatically create a shipment when an invoice is created.

The problem I have is with the final part of the code to send the email once the shipment has been created.

I wanted to ask if anyone can notice what is wrong with the $sendEmail call in my code.

Here's my Observer code for _saveShipment()

        protected function _saveShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order $order, $customerEmailComments = '')
            $transactionSave = Mage::getModel('core/resource_transaction')

            $emailSentStatus = $shipment->getData('email_sent');
                Mage::log("Email has been sent",Zend_Log::INFO,'email.log',true);
                Mage::log("IS FALSE",Zend_Log::INFO,'email.log',true);
//                Mage::log($customerEmailComments,Zend_Log::INFO,'email.log',true);
            if (!is_null($customerEmail) && !$emailSentStatus) {
                $shipment->sendEmail(true, $customerEmailComments);

            return $this;

Thanks for you time...

share|improve this question
Have you checked whether the ifclause is actually true? – user3154108 Aug 4 '14 at 12:52
@user3154108 Hi, yes my if condition is coming back as "FALSE" I'm trying to find out why is isn't send 2014-08-04T13:52:33+00:00 INFO (6): IS FALSE – user1704524 Aug 4 '14 at 13:57
Where is $customerEmail define in if (!is_null($customerEmail)..? – R.S Aug 4 '14 at 14:15
Yeah, R.S is right, $customerEmail does not seem to be defined, giving an eternel null and thus a false in the if. – user3154108 Aug 4 '14 at 14:19
up vote 1 down vote accepted

$customerEmail is not define try

if (!is_null($shipment->getOrder()->getCustomerEmail()) && !$emailSentStatus) {
    $shipment->sendEmail(true, $customerEmailComments);
share|improve this answer
Thankyou, that solved it $customerEmail was not defined – user1704524 Aug 4 '14 at 14:37

Just change the position

$shipment->sendEmail(true, $customerEmailComments);


$shipment->sendEmail(true, $customerEmailComments);

Also sales Shipment email sendEmail() depends on condition:Mage::helper('sales')->canSendNewShipmentEmail($storeId)

Check Shipment setting is enable from admin

enter image description here

share|improve this answer
Thankyou for you response, I have made the changes and checked in admin but I am still not getting an email sent and the log still says 2014-08-04T14:21:07+00:00 INFO (6): IS FALSE :( – user1704524 Aug 4 '14 at 14:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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