From c019875a24610acc304641aa7b88fceff55272b5 Mon Sep 17 00:00:00 2001 From: grandeljay Date: Thu, 16 Jun 2022 20:21:42 +0200 Subject: [PATCH] Save notification time when sending email succeeded --- src/api/wishlists.php | 16 +++++++++------- src/classes/email.php | 4 +++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/api/wishlists.php b/src/api/wishlists.php index c7077368..af5d88cc 100644 --- a/src/api/wishlists.php +++ b/src/api/wishlists.php @@ -86,15 +86,17 @@ switch ($_SERVER['REQUEST_METHOD']) { $user = new User($wishlist['user']); $emailRequest = new Email($user->email, __('Wish request'), $mjml); - $emailRequest->send(); + $success = $emailRequest->send(); /** Save date to database */ - $database - ->query( - 'UPDATE `wishlists` - SET `notification_sent` = CURRENT_TIMESTAMP - WHERE `id` = ' . $wishlist['id'] . ';' - ); + if (true === $success) { + $database + ->query( + 'UPDATE `wishlists` + SET `notification_sent` = CURRENT_TIMESTAMP + WHERE `id` = ' . $wishlist['id'] . ';' + ); + } } $response['success'] = true; diff --git a/src/classes/email.php b/src/classes/email.php index 9bff5866..4827daaa 100644 --- a/src/classes/email.php +++ b/src/classes/email.php @@ -23,7 +23,7 @@ class Email ) { } - public function send() + public function send(): bool { global $options; @@ -56,5 +56,7 @@ class Email ); $success = mail($to, $subject, $message, $headers); + + return $success } }