murph-doc/docs/utils/mail.md
Simon Vieille 385af624a6
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
update theme
2023-02-09 21:50:06 +01:00

46 lines
1.5 KiB
Markdown

# Mail
`App\Core\Notification\MailNotifier` is a service and helps you to create a mail using twig template.
Useful methods:
* `setRecipients(array $recipients): MailNotifier`
* `setBccRecipients(array $bccRecipients): MailNotifier`
* `setSubject(?string $subject): MailNotifier`
* `setFrom($from): MailNotifier`
* `setReplyTo($replyTo): MailNotifier`
* `setAttachments(array $attachments): MailNotifier`
* `addRecipient(string $email, bool $isBcc = false): MailNotifier`
* `addRecipients(array $emails, bool $isBcc = false): MailNotifier`
* `addRecipientByUser(\App\Entity\User $user, bool $isBcc = false): self`
* `addRecipientsByUsers($users, bool $isBcc = false): self`
* `addAttachment(string $attachment): MailNotifier`
* `addAttachments(array $attachments): MailNotifier`
* `init(): MailNotifier`
* `notify(string $template, array $data = [], string $type = 'text/html'): MailNotifier`
Exemple:
```php-inline
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
])
;
}
```