From 7365651d0f7f1e82b940a45f9f4b1851475928b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petra=20Mi=C5=A1eta?= Date: Wed, 14 Feb 2024 16:05:07 +0100 Subject: [PATCH 1/3] IOTA-677 add method to send mail to users in bcc --- bundle/Helper/MailHelper.php | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bundle/Helper/MailHelper.php b/bundle/Helper/MailHelper.php index 6cd3bf8c..e8e9c5cd 100644 --- a/bundle/Helper/MailHelper.php +++ b/bundle/Helper/MailHelper.php @@ -68,6 +68,48 @@ public function sendMail(array|string $receivers, string $subject, string $templ $this->mailer->send($email); } + /** + * Sends a group mail to users in bcc. + * + * Sender and recipient are set to sender + * + * Sender can be: + * a string: info@netgen.io + * an array: array( 'info@netgen.io' => 'Netgen Site' ) + * + * Bcc can be: + * a string: info@netgen.io + * or: + * array( 'info@netgen.io' => 'Netgen Site' ) or + * array( 'info@netgen.io', 'example@netgen.io' ) or + * array( 'info@netgen.io' => 'Netgen Site', 'example@netgen.io' => 'Example' ) + * + * @param string|string[] $receivers + * @param array $parameters + * @param string|string[]|null $sender + */ + public function sendGroupMail(array|string $bcc, string $subject, string $template, array $parameters = [], array|string|null $sender = null): void + { + + try { + $senderAddress = $this->createSenderAddress($sender); + } catch (InvalidArgumentException $e) { + $this->logger->error($e->getMessage()); + + return; + } + + $email = (new Email()) + ->from($senderAddress) + ->sender($senderAddress) + ->to($senderAddress) + ->bcc(...$this->createReceiverAddresses($bcc)) + ->subject($this->translator->trans($subject, [], 'ngsite_mail')) + ->html($this->twig->render($template, $parameters)); + + $this->mailer->send($email); + } + /** * Creates a sender address from provided value. * If sender is not provided (if it is null), it attempts to get the sender from the parameters: From 6aa05498ac477c27c01363265527b0a049440157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petra=20Mi=C5=A1eta?= Date: Wed, 14 Feb 2024 16:48:11 +0100 Subject: [PATCH 2/3] IOTA-677 run cs fixer --- bundle/Helper/MailHelper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/bundle/Helper/MailHelper.php b/bundle/Helper/MailHelper.php index e8e9c5cd..766a64ac 100644 --- a/bundle/Helper/MailHelper.php +++ b/bundle/Helper/MailHelper.php @@ -90,7 +90,6 @@ public function sendMail(array|string $receivers, string $subject, string $templ */ public function sendGroupMail(array|string $bcc, string $subject, string $template, array $parameters = [], array|string|null $sender = null): void { - try { $senderAddress = $this->createSenderAddress($sender); } catch (InvalidArgumentException $e) { From 1770d5975b990bc3cd71ed75ba19e57fa5caaf2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petra=20Mi=C5=A1eta?= Date: Wed, 14 Feb 2024 16:51:09 +0100 Subject: [PATCH 3/3] IOTA-677 fix phpstan errors --- bundle/Helper/MailHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/Helper/MailHelper.php b/bundle/Helper/MailHelper.php index 766a64ac..0fc47871 100644 --- a/bundle/Helper/MailHelper.php +++ b/bundle/Helper/MailHelper.php @@ -84,9 +84,9 @@ public function sendMail(array|string $receivers, string $subject, string $templ * array( 'info@netgen.io', 'example@netgen.io' ) or * array( 'info@netgen.io' => 'Netgen Site', 'example@netgen.io' => 'Example' ) * - * @param string|string[] $receivers + * @param string|string[] $bcc * @param array $parameters - * @param string|string[]|null $sender + * @param string|string[]|null $sender */ public function sendGroupMail(array|string $bcc, string $subject, string $template, array $parameters = [], array|string|null $sender = null): void {