Skip to content

Commit 43ac3e7

Browse files
committed
minor #11734 Replace SwiftMailer with the new Mailer Component (bocharsky-bw)
This PR was merged into the 4.3 branch. Discussion ---------- Replace SwiftMailer with the new Mailer Component Leverage Symfony Mailer component in an example of Messenger code block Commits ------- 77b0d47 Replace SwiftMailer with the new Mailer Component
2 parents 342640d + 77b0d47 commit 43ac3e7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

components/messenger.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,17 @@ you can create your own message sender::
214214
namespace App\MessageSender;
215215

216216
use App\Message\ImportantAction;
217+
use Symfony\Component\Mailer\MailerInterface;
217218
use Symfony\Component\Messenger\Envelope;
218219
use Symfony\Component\Messenger\Transport\Sender\SenderInterface;
220+
use Symfony\Component\Mime\Email;
219221

220222
class ImportantActionToEmailSender implements SenderInterface
221223
{
222224
private $mailer;
223225
private $toEmail;
224226

225-
public function __construct(\Swift_Mailer $mailer, string $toEmail)
227+
public function __construct(MailerInterface $mailer, string $toEmail)
226228
{
227229
$this->mailer = $mailer;
228230
$this->toEmail = $toEmail;
@@ -237,12 +239,10 @@ you can create your own message sender::
237239
}
238240

239241
$this->mailer->send(
240-
(new \Swift_Message('Important action made'))
241-
->setTo($this->toEmail)
242-
->setBody(
243-
'<h1>Important action</h1><p>Made by '.$message->getUsername().'</p>',
244-
'text/html'
245-
)
242+
(new Email())
243+
->to($this->toEmail)
244+
->subject('Important action made')
245+
->html('<h1>Important action</h1><p>Made by '.$message->getUsername().'</p>')
246246
);
247247

248248
return $envelope;

0 commit comments

Comments
 (0)