getResource(); $this->send( $resource->getType(), \sprintf('Neue Buchung: %s am %s', $resource->getLabel(), $booking->getDate()->format('d.m.Y')), 'email/booking_created', ['booking' => $booking], ); } /** * One mail for a whole series, not one per occurrence. * * A year of weekly bookings is the same act and would otherwise arrive as fifty-two mails in * one second -- the same reason AuditLogger records a series once rather than per day. */ public function seriesCreated(SeriesResult $result): void { if ($result->isCompletelyBlocked()) { return; } $series = $result->series; $resource = $series->getResource(); $this->send( $resource->getType(), \sprintf('Neue Serienbuchung: %s ab %s', $resource->getLabel(), $series->getStartDate()->format('d.m.Y')), 'email/series_created', ['result' => $result, 'series' => $series], ); } /** * @param string $template the template pair's basename; both .html.twig and * .txt.twig of it are rendered * @param array $context */ private function send(ResourceType $type, string $subject, string $template, array $context): void { $recipients = $this->settings->recipientsFor($type); if ([] === $recipients) { return; } foreach ($recipients as $recipient) { // A fresh message per recipient: ->to() on a reused one appends rather than replaces, // which would put the whole list back on everybody's copy. $email = (new TemplatedEmail()) ->from(new Address($this->sender, 'E&P Platz')) ->to($recipient) ->subject($subject) ->htmlTemplate($template.'.html.twig') ->textTemplate($template.'.txt.twig') ->context($context); try { $this->mailer->send($email); } catch (\Throwable $e) { // Caught per recipient, so one unreachable address does not cost the others theirs. // \Throwable rather than TransportExceptionInterface because the templates are // rendered inside send(): a typo in one of them would otherwise surface as a failed // booking, which is exactly what this class promises never to do. $this->logger->error('Booking notification could not be sent.', [ 'subject' => $subject, 'recipient' => $recipient, 'exception' => $e, ]); } } } }