Skip to content

[Notifier] Global from header not being picked up for emails, or error message incorrect #47313

@jdelaune

Description

@jdelaune

Symfony version(s) affected

6.1.0

Description

We have setup a global From header for emails like the documentation asks e.g.

# config/packages/dev/mailer.yaml
framework:
    mailer:
        headers:
            From: 'Fabien <fabien@example.com>'

However when we go to send an email via the notifier component we get this error:

To send the "X" notification by email, you should either configure a global "from" header, set a sender in the global "envelope" of the mailer configuration or set a "from" header in the "asEmailMessage()" method.

We have done the first option of configure a global "from" header yet we get this error and the email doesn't send.

Is there a bug in the notifier component or is this intended and the error message is wrong?

How to reproduce

Set a global from header:

# config/packages/dev/mailer.yaml
framework:
    mailer:
        headers:
            From: 'Fabien <fabien@example.com>'

Send a notification via email using the Notifier component. e.g.

// src/Controller/InvoiceController.php
namespace App\Controller;

use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\NotifierInterface;
use Symfony\Component\Notifier\Recipient\Recipient;

class InvoiceController extends AbstractController
{
    #[Route('/invoice/create')]
    public function create(NotifierInterface $notifier)
    {
        // ...

        // Create a Notification that has to be sent
        // using the "email" channel
        $notification = (new Notification('New Invoice', ['email']))
            ->content('You got a new invoice for 15 EUR.')
        ;

        // The receiver of the Notification
        $recipient = new Recipient(
            $user->getEmail(),
            $user->getPhonenumber()
        );

        // Send the notification to the recipient
        $notifier->send($notification, $recipient);

        // ...
    }
}

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy