htmlTemplate('email/order.html.twig') ->subject('Abiball Ticket') ->from(new Address($this->senderMail, 'Noreply')) ->to(new Address($payment->getCustomer()?->getEmail(), $payment->getCustomer()?->getFirstname() . ' ' . $payment->getCustomer()?->getLastname())) ->context([ 'payment' => $payment, ]); $acc = 0; foreach ($this->generateTicket($payment->getCustomer()?->getTickets()) as $pdf) { $mail->attach($pdf, 'tickets-'.++$acc.'.pdf', 'application/pdf'); } $this->mailer->send($mail); } private function generateTicket(Collection $tickets): array { $ticketChunks = array_chunk($tickets->toArray(), 3); $pdfs = []; foreach ($ticketChunks as $ticket) { $pdfs[] = (new DompdfWrapper(new DompdfFactory()))->getPdf($this->twig->render('email/pdf.html.twig', ['tickets' => $ticket])); } return $pdfs; } }