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...

  • 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)..? – Renon Stewart 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

$customerEmail is not define try

if (!is_null($shipment->getOrder()->getCustomerEmail()) && !$emailSentStatus) {
    $shipment->sendEmail(true, $customerEmailComments);
  • 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

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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