From ea7b1a0febf0ac99385fb09585357d839367a51a Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sun, 2 Jun 2019 11:46:57 -0500 Subject: [PATCH] survey email hook --- index.php | 27 +++++++++++++++++++++++++++ src/.env.example | 1 + 2 files changed, 28 insertions(+) diff --git a/index.php b/index.php index 79dda96..1739364 100644 --- a/index.php +++ b/index.php @@ -94,6 +94,33 @@ $router->get('/admin/orders', function () { include 'views/common/footer.php'; }); +$router->get('/admin/send-survey', function () { + $guests = R::findAll('guests', ' order by name asc '); + $client = new Postmark\PostmarkClient($_SERVER['POSTMARK_API_KEY']); + + foreach ($guests as $guest) { + try { + $client->sendEmailWithTemplate( + $_SERVER['POSTMARK_FROM'], + $guest->email, + $_SERVER['POSTMARK_SURVEY_TEMPLATE'], + [ + 'name' => $guest->name, + 'product_name' => 'Dinner in the Woods ' . date('Y'), + ], + true, //inline css + null, //tag + true, //track opens + null, //reply to + null //cc + ); + echo 'Sent email to ' . $guest->email . '
'; + } catch (Exception $e) { + echo 'FAILED to send email to ' . $guest->email . '
'; + } + } +}); + $router->get('/admin/guests/export', function () { R::csv('SELECT * FROM guests', [], [ 'id', diff --git a/src/.env.example b/src/.env.example index 2b3e4f8..df3f81b 100644 --- a/src/.env.example +++ b/src/.env.example @@ -16,6 +16,7 @@ POSTMARK_API_KEY="special" POSTMARK_TEMPLATE="identifier_for_template" POSTMARK_TEMPLATE_STRIPE_INVOICE="identifier_for_template" POSTMARK_TEMPLATE_STRIPE_RECEIPT="id_for_template" +POSTMARK_SURVEY_TEMPLATE="id_for_template" POSTMARK_REMINDER_TEMPLATE="identifier_for_reminder_template" POSTMARK_GUEST_TEMPLATE="identifier_for_template" POSTMARK_FROM="sender@email.com"