-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
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