diff options
author | Jonas Kohl | 2024-12-26 20:12:34 +0100 |
---|---|---|
committer | Jonas Kohl | 2024-12-26 20:12:34 +0100 |
commit | 686fff945e0b4697aa74da404ce90534bb7b121d (patch) | |
tree | cb5582c8d118cb480f2978fa821950f4a2259401 /src/application/jobs | |
parent | 11fed2c8ce3dd38fe686e7b27db738f64373fe3d (diff) |
Add async email and topic subscribingv0.7.2
Diffstat (limited to 'src/application/jobs')
-rw-r--r-- | src/application/jobs/email.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/application/jobs/email.php b/src/application/jobs/email.php new file mode 100644 index 0000000..8bb97dc --- /dev/null +++ b/src/application/jobs/email.php @@ -0,0 +1,33 @@ +<?php + +use mystic\forum\orm\PendingEmail; +use Symfony\Component\Mailer\Exception\TransportExceptionInterface; +use Symfony\Component\Mailer\Transport; +use Symfony\Component\Mime\Email; + +check_sapi(); + +$db = get_db(); + +/** @var PendingEmail[] $pendingEmails */ +$pendingEmails = $db->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); +} |