/** * 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]); }
/** * Method that the user can use to send the voucher to their contacts */ public function emailVoucher() { $layout_html = new JLayoutFile('chclient_alert', JPATH_ROOT . '/components/com_chclient/layouts'); $status = ''; // get the booking $booking = $this->getBooking(); if (!$booking) { $status = 'danger'; } // check the emails $emails = array_map('trim', explode(',', CHLib::input()->getString('emails'))); if (!$emails) { $status = 'danger'; } foreach ($emails as $email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $status = 'danger'; } } // return if errors detected if ($status == 'danger') { return $layout_html->render(['status' => $status, 'message' => CHClient::string('error_incorrect_data')]); } // prepare mail $mailer = JFactory::getMailer(); $config = JFactory::getConfig(); $sender = array($config->get('mailfrom'), $config->get('fromname')); // mail content $mailer->setSubject($booking->hotel->title . ' - ' . $booking->voucher); $mailer->IsHTML(true); $mailer->Encoding = 'base64'; $mailer->setBody(CHClientDisplay::renderVoucher($booking)); // send emails foreach ($emails as $notification_email) { if ($notification_email) { $mailer->setSender($sender); $mailer->addRecipient($notification_email); try { $mailer->Send(); } catch (Exception $e) { // log errors } $mailer->ClearAddresses(); } } return $layout_html->render(['status' => 'success', 'message' => CHClient::string('emails_sent')]); }
/** * Print Voucher */ private function printVoucher() { // render and quit app CHLib::rawExit(CHClientDisplay::renderVoucher($this->booking)); }