/** * Render the voucher html * * @param object $booking * @return string */ static function renderVoucher($booking) { // render voucher $layout_html = new JLayoutFile('chclient_email_voucher', JPATH_ROOT . '/components/com_chclient/layouts'); $layout_css = new JLayoutFile('chclient_email_css', JPATH_ROOT . '/components/com_chclient/layouts'); $html = $layout_html->render(['booking' => $booking]); $css = 'a { color:' . $booking->app->color . ';}' . $layout_css->render([]); return CHLibEmail::inlineCSS($html, $css); }
/** * Send notification emails */ public static function emailNotification($booking, $card = false, $cancellation = false) { // prepare mail $mailer = JFactory::getMailer(); $mailer->IsHTML(true); $mailer->Encoding = 'base64'; $config = JFactory::getConfig(); $sender = array($config->get('mailfrom'), $config->get('fromname')); // mail content $subject = $booking->hotel->title . ' - ' . $booking->booking_id; if ($cancellation) { $subject .= ' - ' . CHClient::string('cancellation'); } $mailer->setSubject($subject); $mailer->setBody(CHClientDisplay::renderVoucher($booking)); // voucher notification emails $hotel_notify = array_map('trim', explode(',', $booking->hotel->notify_voucher)); $app_notify = array_map('trim', explode(',', $booking->app->notify_voucher)); $notification_emails = array_values(array_merge($hotel_notify, $app_notify)); // send mails to notification list first if ($notification_emails) { foreach ($notification_emails as $notification_email) { if ($notification_email) { $mailer->setSender($sender); $mailer->addRecipient($notification_email); try { $mailer->Send(); } catch (Exception $e) { // log errors } $mailer->ClearAddresses(); } } } // send mail to guest $mailer->addRecipient($booking->customer->email); $mailer->setSender($sender); try { $mailer->Send(); } catch (Exception $e) { // log errors } $mailer->ClearAddresses(); // send card details email if ($card) { // generate card email $title = $booking->hotel->title . ' - ' . $booking->booking_id . ' - ' . CHClient::string('card_details'); $mailer->setSubject($title); // generate email body $layout_css = new JLayoutFile('chclient_email_css', JPATH_ROOT . '/components/com_chclient/layouts'); $layout_html = new JLayoutFile('chclient_email_card', JPATH_ROOT . '/components/com_chclient/layouts'); $html = $layout_html->render(['booking' => $booking, 'card' => $card, 'title' => $title]); $css = 'a { color:' . $booking->app->color . ';}' . $layout_css->render([]); $body = CHLibEmail::inlineCSS($html, $css); $mailer->setBody($body); // send to card notifications emails $hotel_notify = explode(',', $booking->hotel->notify_card); $app_notify = explode(',', $booking->app->notify_card); $notification_emails = array_values(array_merge($hotel_notify, $app_notify)); if ($notification_emails) { foreach ($notification_emails as $notification_email) { if ($notification_email) { $mailer->setSender($sender); $mailer->addRecipient($notification_email); try { $mailer->Send(); } catch (Exception $e) { // log errors } $mailer->ClearAddresses(); } } } } // execute notify plugins JPluginHelper::importPlugin('chclient'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onNotify', [$booking]); }