Skip to content

Commit 0237d8d

Browse files
fix: [doc] Use the Mailer component instead of SwiftMailer (#1488)
1 parent 43b39f6 commit 0237d8d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

core/events.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9090
use Symfony\Component\HttpFoundation\Request;
9191
use Symfony\Component\HttpKernel\Event\ViewEvent;
9292
use Symfony\Component\HttpKernel\KernelEvents;
93+
use Symfony\Component\Mime\Email;
94+
use Symfony\Component\Mailer\MailerInterface;
9395

9496
final class BookMailSubscriber implements EventSubscriberInterface
9597
{
9698
private $mailer;
9799

98-
public function __construct(\Swift_Mailer $mailer)
100+
public function __construct(MailerInterface $mailer)
99101
{
100102
$this->mailer = $mailer;
101103
}
@@ -116,10 +118,11 @@ final class BookMailSubscriber implements EventSubscriberInterface
116118
return;
117119
}
118120

119-
$message = (new \Swift_Message('A new book has been added'))
120-
->setFrom('[email protected]')
121-
->setTo('[email protected]')
122-
->setBody(sprintf('The book #%d has been added.', $book->getId()));
121+
$message = (new Email())
122+
123+
124+
->subject('A new book has been added')
125+
->text(sprintf('The book #%d has been added.', $book->getId()));
123126

124127
$this->mailer->send($message);
125128
}

0 commit comments

Comments
 (0)