How to send a custom e-mail?

By default, Sylius only sends emails for essential flows like order confirmation. However, you can easily extend this by configuring custom logic and templates using the built-in SyliusMailerBundle.

This guide shows how to send an email to all administrators when a product variant becomes out of stock.

circle-check

1. Create the Email Template

This file defines how your email will look. Sylius expects a subject block and a content block.

{# templates/email/out_of_stock.html.twig #}

{% extends '@SyliusCore/Email/layout.html.twig' %}

{% block subject %}
    One of your products is out of stock.
{% endblock %}

{% block content %}
    <div style="text-align: center; margin-bottom: 30px;">
        The variant
        <div style="margin: 10px 0;">
            <span style="border: 1px solid #eee; padding: 10px; color: #1abb9c; font-size: 28px;">
                {% if variant.name %}
                  {{ variant.name }}
                {% else %}
                  {{ variant.product.name }}
                {% endif %}
            </span>
        </div>
        is currently out of stock.
    </div>
{% endblock %}
circle-check

2. Register the Email in Mailer Configuration

This registers your custom email under the Sylius Mailer system.

circle-exclamation

3. Create a Custom Email Manager

This class orchestrates stock checking and email sending.


4. Register the Service

Add this to your config/services.yaml:


5. Create a callback for order_payment

Create the Event Listener

Register the Listener

circle-check

✅ Test the Results

1. Create a product with tracked stock

  • Go to the Admin PanelCatalogProducts Create .

  • Create a simple product and reduce one of its variant stock levels to 3.

  • Ensure that the product is tracked, and the stock is managed (i.e., onHand: 3, tracked: true).

2. Place an Order

  • From the shop, place an order for this product, quantity 3.

  • Open the admin panel and complete the payment on the placed order.

3. Verify Email Sent

You can use one of these tools to check if the email was sent:

circle-check
circle-exclamation

Last updated

Was this helpful?