Magento: send status changed with custom email template

Magento: send status changed with custom email template

September 10, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: send status changed with custom email template

Sending Custom Email Templates for Magento Order Status Changes

As you’re working on enhancing your PayPal extension for Magento, you’ve encountered the need to send tailored email notifications based on order status changes. The built-in sendOrderUpdateEmail() function is a powerful tool that can be utilized to achieve this customization.

Understanding the Current Code

Your current implementation uses the sendOrderUpdateEmail() method within your PayPal order controller for each different status. This function sends an email based on Magento’s default templates, which might not provide the level of customization you’re looking for.

$order->sendOrderUpdateEmail();
$order->setEmailSent(true);

Implementing Custom Email Templates

To send a custom email template for each status, you’ll need to create new templates and then call them specifically in your controller. Let’s walk through the process step-by-step.

  1. Create Your Custom Email Templates

    • Navigate to app/design/frontend/default/your_template/email (or the appropriate theme folder)
    • Create a new XML file, e.g., cancelled_order.html
  2. Call the Custom Template in Your Controller

Replace your existing function calls with this updated code:

switch ($orderStatus) {
    case 'your_status_here':
        $emailTemplate = "cancelled_order"; // Name of your custom template file without .html extension
        $order->setCustomerEmailTemplate($emailTemplate);
        break;
}

if (!$order->getEmailSent()) {
    $order->sendOrderUpdateEmail();
    $order->setEmailSent(true);
}

In this example, when the order status matches your_status_here, Magento will use the custom template you created. The setCustomerEmailTemplate() function specifies which template to load.

Best Practices and Additional Configurations

  • Use placeholders in your templates: You can include placeholders like {order_id} or {customer_name} in your email content, which will be automatically replaced with the appropriate data.
  • Configure your email settings: Ensure that your email configuration (sender name, reply-to address, etc.) is properly set up under Stores > Settings > Configuration > Sales > Sales Emails.

Conclusion

Sending custom email templates for each order status in Magento requires a combination of creating the templates and then instructing Magento to use them specifically based on the status change. By following this approach, you can provide your customers with tailored, informative messages that enhance their shopping experience.

Remember that Magento’s extensibility allows for such customizations, enabling you to create a more personalized touchpoint between your store and your clients.

For further reference on Magento email template creation and configuration, I recommend checking out the official Magento developer documentation.

Don’t hesitate to explore more features and integrations offered by LaravelCompany’s Magento services for a seamless e-commerce experience.

Extensions Themes Email Orders

Our network