Search by

sparklink / email-errors-bundle

sparklink

Symfony bundle to send errors by email

Package info

github.com/sparklink-pro/EmailErrorsBundle

Type:symfony-bundle

pkg:composer/sparklink/email-errors-bundle

Statistics

Installs: 441

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 1

1.4.1 2026-12-03 08:32 UTC

This package is auto-updated.

Last update: 2026-12-03 08:33:58 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

This Symfony bundle provides a way to send email notifications when an error occurs in your application.

Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

composer require sparklink/email-errors-bundle

Symfony Flex Installation

Accept the contrib recipes installation from Symfony Flex

-  WARNING  sparklink/email-errors-bundle (1.0.0): From github.com/symfony/recipes-contrib
    The recipe for this package comes from the "contrib" repository, which is open to community contributions.
    Do you want to execute this recipe?
    [y] Yes
    [n] No
    [a] Yes for all packages, only for the current installation session
    [p] Yes permanently, never ask again for this project
    (defaults to n): 

Manual Installation

Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    Sparklink\EmailErrorsBundle\EmailErrorsBundle::class => ['all' => true],
];

Configure the Bundle

Create a new file config/packages/email_errors.yaml and add the following configuration:

# config/packages/email_errors.yaml
email_errors:
  from: "%env(resolve:MAILER_ERRORS_FROM)%"
  to: "%env(resolve:MAILER_ERRORS_TO)%"
  ignored_exception_classes: []
  graphql: true

when@dev:
  email_errors:
    enabled: false

when@test:
  email_errors:
    enabled: false
Option Default Description
enabled true When false, nothing is sent. It is read when the container is built: disable the bundle per environment with when@<env> as above, not with an environment variable (an %env()% value always counts as enabled).
from required Sender address of the emails.
to required Recipient address of the emails.
subject Exception Start of the email subject, followed by the error message.
mailer_service mailer.mailer Id of the service sending the emails, a Symfony\Component\Mailer\MailerInterface.
ignored_exception_classes [] Errors not sent, by exact class: a subclass, or an error whose previous exception has this class, is still sent. A GraphQL error usually has the class GraphQL\Error\Error, whatever exception it wraps: ignore it by message instead.
ignored_exception_messages [] Errors not sent when their message contains one of these strings (case-sensitive).
ignored_ip_addresses [] Errors of requests coming from one of these IP addresses are not sent. Exact addresses only (no ranges), compared to the client IPs given by Request::getClientIps(): behind a reverse proxy, configure Symfony's trusted proxies, otherwise only the proxy's address is seen. Errors without a request (commands, workers) are not concerned.
graphql false Also sends the errors returned in the GraphQL responses of OverblogGraphQLBundle, which are not thrown and so never reach the exception listener.
throttle 0 See Throttling.
monolog_level critical See Sending log records (Monolog).

Security panel

When the project uses the Symfony security component, the Request block of error emails starts with a Security panel showing the authentication state of the request that triggered the error: authenticated or not, user identifier, roles, and whether a session cookie was sent. This makes it possible to diagnose errors caused by expired sessions — typically GraphQL Cannot query field errors on fields hidden from anonymous users by a public: "@=hasRole(...)" expression, for which a Probable cause panel is also added to the Details block.

The panel is enabled automatically when the security.token_storage service exists; nothing to configure.

The Probable cause panel only ever appears with graphql: true: Cannot query field errors are returned in the GraphQL response rather than thrown, so they only reach the mailer through the bundle's GraphQL listener.

Details block

Panels about the error itself rather than the request are grouped in a Details block, at the top of the email, before the stack traces. It is there even when the error has no request (command, Messenger worker, record logged by a command):

  • Probable cause (see above);
  • Validation errors: the constraint violations of the exception or of one of its previous exceptions (any exception with a getViolations() method, such as Symfony's ValidationFailedException), with their property path and code. A generic "Invalid payload" error then shows which constraint failed. Each violation shows its untranslated message (its template: a translation key such as user.email_taken, or the English message of a Symfony constraint) before the message as the user saw it, in their language: email: user.email_taken — 이 이메일 주소로 등록된 계정이 이미 있습니다 (code …);
  • Log record, for the records sent by the Monolog handler (see below).

Redaction of sensitive values

Since these emails travel through a mail provider and sit in a shared mailbox, values that would allow whoever reads them to impersonate the user are redacted (only the first 8 characters are kept):

  • cookies whose name contains sess, token, auth or remember (e.g. PHPSESSID, REMEMBERME), the configured session cookie, and cf_clearance;
  • the Authorization, Cookie, PHP-Auth-*, X-Api-Key, X-Auth-Token and X-CSRF-Token headers;
  • session keys starting with _security (the serialized security token embeds the user object, password hash included).

Request parameters whose key contains password, passwd or secret are replaced by [redacted] with no prefix kept, at any depth, in the GET parameters, the POST parameters and a JSON request body (e.g. GraphQL variables of a sign-up mutation). This also applies inside a parameter holding a JSON string, such as the operations field of a GraphQL multipart request (file upload). A password written as a literal inside a GraphQL query string, rather than passed as a variable, is not detected.

The stack trace is not redacted: with zend.exception_ignore_args = Off (the php.ini-development default), it shows the arguments of each call, a password passed to a function included. Keep zend.exception_ignore_args = On in production, as in php.ini-production.

Throttling

An error repeated in a loop (a page called again and again, a command run every minute) would send the same email each time. With throttle (in seconds, 0 by default = off), the same error is sent at most once during that time. Two errors are the same when their whole chain of previous exceptions matches (class, message, file and line of each) and so do their constraint violations: GraphQL errors wrapping different exceptions, or two "Invalid payload" errors with different violations, are all sent. A violation counts by its untranslated message, so the same violation met in several languages is the same error:

# config/packages/email_errors.yaml
email_errors:
  throttle: 3600

The errors already sent are kept in the cache.app cache pool. An email that could not be sent (the mailer threw an exception) is not throttled: the error is sent again the next time.

With an asynchronous mailer (Symfony Messenger), the mailer only puts the email in the queue: a failure in the worker happens after the error was recorded as sent, so the same error is not sent again until the throttle delay has passed. Watch the failed messages of the transport (messenger:failed:show) if emails go missing.

Sending log records (Monolog)

When Monolog 3 is installed, the bundle defines a Monolog handler, email_errors.monolog_handler, which sends the records it receives through the same mailer as the exceptions: same template, filters, redaction and throttling. The exception of the record (['exception' => $e] in its context) is sent if there is one, otherwise its message, with the stack trace of where it was logged. A Log record panel shows the message, channel and level of the record, its context (the exception aside) and its extra data, redacted like request parameters. The context is not part of the throttling: two records with the same message and different context values are the same error.

It only sends the records from its level, critical by default (option monolog_level: a Monolog level name — debug, info, notice, warning, error, critical, alert, emergency, in any case — or value; an invalid level is reported when the container is built, unless it comes from an environment variable). Use it for one channel, for example the alerts of a synchronisation run by a command, which the exception listener doesn't see:

# config/packages/monolog.yaml
monolog:
    channels: [crm]
    handlers:
        crm_alerts:
            type: service
            id: email_errors.monolog_handler
            channels: [crm]

Then $crmLogger->critical('No sync succeeded for 15 minutes') sends an email. Avoid using it for every channel: Symfony already logs each uncaught exception of a page as critical in the request channel, which the exception listener sends too.

Errors of commands and Messenger workers

The exception listener only sees the errors of pages (kernel.exception). Symfony already logs the other uncaught errors as critical, with the exception in the context:

  • an exception thrown by a console command, in the console channel;
  • a Messenger message given up after its retries, in the messenger channel (each retry is only logged as a warning).

Listening to these channels is enough to receive them by email, with the exception and its stack trace, and the command line in the Log record panel:

# config/packages/monolog.yaml
monolog:
    handlers:
        email_errors:
            type: service
            id: email_errors.monolog_handler
            channels: [console, messenger]

An exception caught by the command itself (a try/catch returning Command::FAILURE) is not logged by Symfony: log it as critical to receive it. A command that ends with a non-zero exit code without an exception sends nothing.

When the bundle is disabled (enabled: false), the handler still exists but sends nothing, so the Monolog configuration keeps working. With Monolog 2, on the contrary, the handler is not defined at all: a Monolog configuration using it fails when the container is built.

An error raised while an email is being sent, and reported again to the mailer (for example the "Error sending exception email" record, if the handler listens to the main channel with the error level), is not sent: it would fail the same way, again and again.