I want to optimize the work with swiftmailer. Look it’s a good idea?
require_once 'vendor/swiftmailer/swiftmailer/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('host.com', 25);
$mailer = Swift_Mailer::newInstance($transport);
return $mailer;
};```
****
```$app->get("/send", function () use ($app,$database) {
$mailer = $app->mailer;
$html_body = 'News<br>'.htmlspecialchars($comment);
$message = Swift_Message::newInstance('New')
->setFrom(array('noreply@host.com' => 'Notify'))
->setTo(array('host@host.com' => 'host'))
->setBody('News.')->addPart($html_body, 'text/html');
$numSent = $mailer->send($message);
});```