Programmatically send shipping/tracking mail

Programmatically send shipping/tracking mail

July 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Programmatically send shipping/tracking mail

Sending Shipping Confirmation Emails in Magento 1.4

Magento provides robust functionality for sending automated emails, including shipment confirmation emails to customers when an order is shipped successfully. However, the standard Magento interface might not cover all your needs, especially if you require programmatic control over these email notifications.

The code snippet provided shows a good starting point for adding tracking information to a shipment programmatically. It correctly loads the order and creates the shipment using the Mage_Sales_Model_Order_Shipment_Api class. After creating the shipment, it iterates through all shipments linked to the specific order and adds tracking data.

Sending Shipment Confirmation Emails Programmatically

To send a confirmation email when a new shipment is created programmatically, you need to extend this logic to use Magento’s built-in email functionality. Here’s how to accomplish this:

First, make sure you have an active and configured transactional email template for ‘New Shipment Created’ in the Magento admin panel. You can find these templates under System > Configuration > Sales > Sales Emails.

Next, you need to create a new shipment confirmation email after adding tracking information. You can use the Mage_Core_Model_Email_Template class and its associated methods:

// Load the order and shipment data
$order = Mage::getModel('sales/order')->loadByIncrementId($increment_id);
$shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);

// Create a new email object
$emailTemplate = Mage::getModel('core/email_template');

// Load the shipment confirmation template
$emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $order->getStoreId()))
              ->sendTransactional(
                Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $order->getStoreId()),
                $sender,
                $recipient,
                $replyTo,
                array(
                    'shipment_id' => $shipment->getId(),
                    'increment_id' => $order->getIncrementId(),
                    'store_name' => $order->getData('store_name'),
                )
              );

// If the email is sent successfully, set the order status to shipped
if ($emailTemplate->getSent()) {
    // Update the order status to 'shipped'
    $order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true)->save();
}

This code loads the appropriate transactional email template based on your store configuration. It then sends an email using the recipient’s data and a customizable template with dynamic content.

Remember to replace 'shipment_id', 'increment_id', and 'store_name' in the array with the actual values you need for your specific use case.

Conclusion

Sending shipment confirmation emails programmatically in Magento 1.4 requires extending the base functionality provided by the framework. By leveraging Magento’s built-in email template system, you can create custom email notifications triggered when a new shipment is created or tracking data is added.

For further reference and detailed examples on working with emails in Magento, I recommend checking out our comprehensive guide on Magento email management: https://laravelcompany.com/magento-email-management/.

This guide covers various aspects of customizing and sending emails based on specific events and customer interactions within the Magento ecosystem.

Magento 1 API Themes Admin

Our network