App\Core\Notification\MailNotifier is a service and helps you to create a mail using twig template.
Useful methods:
setRecipients(array $recipients): MailNotifiersetBccRecipients(array $bccRecipients): MailNotifiersetSubject(?string $subject): MailNotifiersetFrom($from): MailNotifiersetReplyTo($replyTo): MailNotifiersetAttachments(array $attachments): MailNotifieraddRecipient(string $email, bool $isBcc = false): MailNotifieraddRecipients(array $emails, bool $isBcc = false): MailNotifieraddRecipientByUser(\App\Entity\User $user, bool $isBcc = false): selfaddRecipientsByUsers($users, bool $isBcc = false): selfaddAttachment(string $attachment): MailNotifieraddAttachments(array $attachments): MailNotifierinit(): MailNotifiernotify(string $template, array $data = [], string $type = 'text/html'): MailNotifier
Exemple:
use App\Core\Notification\MailNotifier;
use App\Repository\UserRepositoryQuery;
public function foo(MailNotifier $notifier, UserRepositoryQuery $query)
{
// ...
$notifier
->init()
->setSubject('Your bill')
->addRecipient('john.doe@example.com')
->addRecipients(array_map(
fn($u) => $u->getEmail(),
$query->create()->where('.isAdmin = true')->find()
), true)
->addAttachment('path/to/bill.pdf')
->notify('mail/bill.html.twig', [
// view params
])
;
}