diff --git a/src/modules/Email/Service.php b/src/modules/Email/Service.php index bfd8c193c..c31c55d39 100644 --- a/src/modules/Email/Service.php +++ b/src/modules/Email/Service.php @@ -32,12 +32,12 @@ class Service implements \Box\InjectionAwareInterface public function getSettingsRoutes() { - return array( - 'history' => array( + return [ + 'history' => [ 'path' => 'email/history', 'label' => 'Email history', - ), - ); + ], + ]; } public function getSearchQuery($data) @@ -145,11 +145,11 @@ class Service implements \Box\InjectionAwareInterface ]; $this->di['validator']->checkRequiredParamsForArray($required, $data); - if (!isset($data['to']) && !isset($data['to_staff']) && !isset($data['to_client'])) { - throw new \Box_Exception('Receiver is not defined. Define to or to_client or to_staff parameter'); + if (!isset($data['to']) && !isset($data['to_staff']) && !isset($data['to_client']) && !isset($data['to_admin'])) { + throw new \Box_Exception('Receiver is not defined. Define to or to_client or to_staff or to_admin parameter'); } $vars = $data; - unset($vars['to'], $vars['to_client'], $vars['to_staff'], $vars['to_name'], $vars['from'], $vars['from_name']); + unset($vars['to'], $vars['to_client'], $vars['to_staff'], $vars['to_name'], $vars['from'], $vars['from_name'], $vars['to_admin']); unset($vars['default_description'], $vars['default_subject'], $vars['default_template'], $vars['code']); // add additional variables to template @@ -167,6 +167,12 @@ class Service implements \Box\InjectionAwareInterface $vars['c'] = $customer; } + // send email to admins + if (isset($data['to_admin']) && $data['to_admin'] > 0) { + $oneStaff = $this->di['db']->findOne('Admin', 'id=?', [$data['to_admin']]); + $vars['c'] = $oneStaff; + } + $db = $this->di['db']; $t = $db->findOne('EmailTemplate', 'action_code = :action', [':action' => $data['code']]); @@ -206,6 +212,10 @@ class Service implements \Box\InjectionAwareInterface $to_name = $staff['name']; $sent = $this->sendMail($to, $from, $subject, $content, $to_name, $from_name, null, $staff['id']); } + } elseif (isset($oneStaff)) { + $to = $oneStaff->email; + $to_name = $oneStaff->name; + $sent = $this->sendMail($to, $from, $subject, $content, $to_name, $from_name, $oneStaff->id); } elseif (isset($customer)) { $to = $customer['email']; $to_name = $customer['first_name'] . ' ' . $customer['last_name']; @@ -604,12 +614,13 @@ class Service implements \Box\InjectionAwareInterface error_log($message); // Prevent mass retries of emails if one of them is "invalid" - if(strpos($message, 'Invalid address:') !== false) { + if (false !== strpos($message, 'Invalid address:')) { try { $this->di['db']->trash($queue); } catch (\Exception $e) { error_log($e->getMessage()); } + return true; } @@ -620,7 +631,7 @@ class Service implements \Box\InjectionAwareInterface ++$queue->tries; $queue->updated_at = date('Y-m-d H:i:s'); $this->di['db']->store($queue); - $maxTries = ( isset($settings['cancel_after']) ) ? $settings['cancel_after'] : 5; + $maxTries = (isset($settings['cancel_after'])) ? $settings['cancel_after'] : 5; if ($queue->tries > $maxTries) { $this->di['db']->trash($queue); } diff --git a/src/modules/Staff/Api/Guest.php b/src/modules/Staff/Api/Guest.php index 787d6e141..9249d4f34 100644 --- a/src/modules/Staff/Api/Guest.php +++ b/src/modules/Staff/Api/Guest.php @@ -124,7 +124,7 @@ class Guest extends \Api_Abstract // send email $email = []; - $email['to_client'] = $reset->admin_id; + $email['to_admin'] = $c->id; $email['code'] = 'mod_staff_password_reset_request'; $email['hash'] = $hash; $emailService = $this->di['mod_service']('email'); diff --git a/src/modules/Staff/Service.php b/src/modules/Staff/Service.php index a785ba0e5..7b05a3f94 100644 --- a/src/modules/Staff/Service.php +++ b/src/modules/Staff/Service.php @@ -709,7 +709,7 @@ class Service implements InjectionAwareInterface // send email $email = []; - $email['to_client'] = $reset->admin_id; + $email['to_admin'] = $c->id; $email['code'] = 'mod_staff_password_reset_approve'; $email['password'] = $new_pass; $emailService = $this->di['mod_service']('email'); diff --git a/src/modules/Staff/html_email/mod_staff_password_reset_approve.html.twig b/src/modules/Staff/html_email/mod_staff_password_reset_approve.html.twig index 54a4ff62f..d8637a28e 100644 --- a/src/modules/Staff/html_email/mod_staff_password_reset_approve.html.twig +++ b/src/modules/Staff/html_email/mod_staff_password_reset_approve.html.twig @@ -2,7 +2,7 @@ {% block content %} {% apply markdown %} -Hello {{ c.first_name }} {{ c.last_name }}, +Hello {{ c.name }}, As you requested, your password for our staff area has now been reset. Your new login details are as follows: diff --git a/src/modules/Staff/html_email/mod_staff_password_reset_request.html.twig b/src/modules/Staff/html_email/mod_staff_password_reset_request.html.twig index 8ae766673..ab742d90c 100644 --- a/src/modules/Staff/html_email/mod_staff_password_reset_request.html.twig +++ b/src/modules/Staff/html_email/mod_staff_password_reset_request.html.twig @@ -2,7 +2,7 @@ {% block content %} {% apply markdown %} -Hello {{ c.first_name }} {{ c.last_name }}, +Hello {{ c.name }}, Recently a request was submitted to reset your password for the staff area. If you did not request this, please ignore this email. It will expire and will not work in 2 hours time.