murph-doc/docs/utils/mail.md

47 lines
1.5 KiB
Markdown
Raw Normal View History

2022-05-07 13:47:17 +02:00
# Mail
2022-05-07 14:12:20 +02:00
`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`
2022-05-07 16:18:25 +02:00
* `addRecipientByUser(\App\Entity\User $user, bool $isBcc = false): self`
* `addRecipientsByUsers($users, bool $isBcc = false): self`
2022-05-07 14:12:20 +02:00
* `addAttachment(string $attachment): MailNotifier`
* `addAttachments(array $attachments): MailNotifier`
* `init(): MailNotifier`
* `notify(string $template, array $data = [], string $type = 'text/html'): MailNotifier`
Exemple:
2023-02-09 21:50:06 +01:00
```php-inline
2022-05-07 14:12:20 +02:00
use App\Core\Notification\MailNotifier;
2022-05-07 16:18:25 +02:00
use App\Repository\UserRepositoryQuery;
2022-05-07 14:12:20 +02:00
2022-05-07 16:18:25 +02:00
public function foo(MailNotifier $notifier, UserRepositoryQuery $query)
2022-05-07 14:12:20 +02:00
{
// ...
$notifier
->init()
->setSubject('Your bill')
->addRecipient('john.doe@example.com')
2022-09-22 19:36:35 +02:00
->addRecipients(array_map(
fn($u) => $u->getEmail(),
$query->create()->where('.isAdmin = true')->find()
), true)
2022-05-07 14:12:20 +02:00
->addAttachment('path/to/bill.pdf')
->notify('mail/bill.html.twig', [
// view params
])
;
}
```