fetchAll(PendingEmail::class); $transport = Transport::fromDsn(getenv("MAILER_DSN")); foreach ($pendingEmails as $pendingEmail) { try { $mail = (new Email) ->from($pendingEmail->sender) ->to($pendingEmail->recipient) ->subject($pendingEmail->subject) ; if (!empty($pendingEmail->htmlBody)) $mail->html($pendingEmail->htmlBody); if (!empty($pendingEmail->plaintextBody)) $mail->text($pendingEmail->plaintextBody); $transport->send($mail); } catch (TransportExceptionInterface $ex) { print_error("Failed to send mail: " . $ex->getMessage() . "\n"); } $db->delete($pendingEmail); }