mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-22 06:32:24 +03:00
Improved rendering for email templates (#611).
This commit is contained in:
parent
1f4438afd2
commit
1d91f6d1c4
3 changed files with 91 additions and 145 deletions
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Appointment Details</title>
|
||||
<title><?= lang('appointment_details_title') ?></title>
|
||||
</head>
|
||||
<body style="font: 13px arial, helvetica, tahoma;">
|
||||
<div class="email-container" style="width: 650px; border: 1px solid #eee;">
|
||||
|
@ -8,63 +8,63 @@
|
|||
height: 45px; padding: 10px 15px;">
|
||||
<strong id="logo" style="color: white; font-size: 20px;
|
||||
text-shadow: 1px 1px 1px #8F8888; margin-top: 10px; display: inline-block">
|
||||
$company_name</strong>
|
||||
<?= $company_name ?></strong>
|
||||
</div>
|
||||
|
||||
<div id="content" style="padding: 10px 15px;">
|
||||
<h2>$email_title</h2>
|
||||
<p>$email_message</p>
|
||||
<h2><?= $email_title ?></h2>
|
||||
<p><?= $email_message ?></p>
|
||||
|
||||
<h2>Appointment Details</h2>
|
||||
<h2><?= lang('appointment_details_title') ?></h2>
|
||||
<table id="appointment-details">
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Service</td>
|
||||
<td style="padding: 3px;">$appointment_service</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('service') ?></td>
|
||||
<td style="padding: 3px;"><?= $appointment_service ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Provider</td>
|
||||
<td style="padding: 3px;">$appointment_provider</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('provider') ?></td>
|
||||
<td style="padding: 3px;"><?= $appointment_provider ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Start</td>
|
||||
<td style="padding: 3px;">$appointment_start_date</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('start') ?></td>
|
||||
<td style="padding: 3px;"><?= $appointment_start_date ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">End</td>
|
||||
<td style="padding: 3px;">$appointment_end_date</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('end') ?></td>
|
||||
<td style="padding: 3px;"><?= $appointment_end_date ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Customer Details</h2>
|
||||
<h2><?= lang('customer_details_title') ?></h2>
|
||||
<table id="customer-details">
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Name</td>
|
||||
<td style="padding: 3px;">$customer_name</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('name') ?></td>
|
||||
<td style="padding: 3px;"><?= $customer_name ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Email</td>
|
||||
<td style="padding: 3px;">$customer_email</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('email') ?></td>
|
||||
<td style="padding: 3px;"><?= $customer_email ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Phone</td>
|
||||
<td style="padding: 3px;">$customer_phone</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('phone_number') ?></td>
|
||||
<td style="padding: 3px;"><?= $customer_phone ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Address</td>
|
||||
<td style="padding: 3px;">$customer_address</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('address') ?></td>
|
||||
<td style="padding: 3px;"><?= $customer_address ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Appointment Link</h2>
|
||||
<a href="$appointment_link" style="width: 600px;">$appointment_link</a>
|
||||
<h2><?= lang('appointment_link_title') ?></h2>
|
||||
<a href="<?= $appointment_link ?>" style="width: 600px;"><?= $appointment_link ?></a>
|
||||
</div>
|
||||
|
||||
<div id="footer" style="padding: 10px; text-align: center; margin-top: 10px;
|
||||
border-top: 1px solid #EEE; background: #FAFAFA;">
|
||||
Powered by
|
||||
<a href="http://easyappointments.org" style="text-decoration: none;">Easy!Appointments</a>
|
||||
<a href="https://easyappointments.org" style="text-decoration: none;">Easy!Appointments</a>
|
||||
|
|
||||
<a href="$company_link" style="text-decoration: none;">$company_name</a>
|
||||
<a href="<?= $company_link ?>" style="text-decoration: none;"><?= $company_name ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>$email_title</title>
|
||||
<title><?= lang('appointment_cancelled_title') ?></title>
|
||||
</head>
|
||||
<body style="font: 13px arial, helvetica, tahoma;">
|
||||
<div class="email-container" style="width: 650px; border: 1px solid #eee;">
|
||||
|
@ -8,63 +8,63 @@
|
|||
height: 45px; padding: 10px 15px;">
|
||||
<strong id="logo" style="color: white; font-size: 20px;
|
||||
text-shadow: 1px 1px 1px #8F8888; margin-top: 10px; display: inline-block">
|
||||
$company_name</strong>
|
||||
<?= $company_name ?></strong>
|
||||
</div>
|
||||
|
||||
<div id="content" style="padding: 10px 15px;">
|
||||
<h2>$email_title</h2>
|
||||
<p>$email_message</p>
|
||||
<h2><?= lang('appointment_cancelled_title') ?></h2>
|
||||
<p><?= lang('appointment_removed_from_schedule') ?></p>
|
||||
|
||||
<h2>Appointment Details</h2>
|
||||
<h2><?= lang('appointment_details_title') ?></h2>
|
||||
<table id="appointment-details">
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Service</td>
|
||||
<td style="padding: 3px;">$appointment_service</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('service') ?></td>
|
||||
<td style="padding: 3px;"><?= $appointment_service ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Provider</td>
|
||||
<td style="padding: 3px;">$appointment_provider</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('provider') ?></td>
|
||||
<td style="padding: 3px;"><?= $appointment_provider ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Date</td>
|
||||
<td style="padding: 3px;">$appointment_date</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('start') ?></td>
|
||||
<td style="padding: 3px;"><?= $appointment_date ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Duration</td>
|
||||
<td style="padding: 3px;">$appointment_duration</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('duration') ?></td>
|
||||
<td style="padding: 3px;"><?= $appointment_duration ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Customer Details</h2>
|
||||
<h2><?= lang('customer_details_title') ?></h2>
|
||||
<table id="customer-details">
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Name</td>
|
||||
<td style="padding: 3px;">$customer_name</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('name') ?></td>
|
||||
<td style="padding: 3px;"><?= $customer_name ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Email</td>
|
||||
<td style="padding: 3px;">$customer_email</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('email') ?></td>
|
||||
<td style="padding: 3px;"><?= $customer_email ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Phone</td>
|
||||
<td style="padding: 3px;">$customer_phone</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('phone_number') ?></td>
|
||||
<td style="padding: 3px;"><?= $customer_phone ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;">Address</td>
|
||||
<td style="padding: 3px;">$customer_address</td>
|
||||
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('address') ?></td>
|
||||
<td style="padding: 3px;"><?= $customer_address ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Reason</h2>
|
||||
<p>$reason</p>
|
||||
<h2><?= lang('reason') ?></h2>
|
||||
<p><?= $reason ?></p>
|
||||
</div>
|
||||
|
||||
<div id="footer" style="padding: 10px; text-align: center; margin-top: 10px;
|
||||
border-top: 1px solid #EEE; background: #FAFAFA;">
|
||||
Powered by
|
||||
<a href="http://easyappointments.org" style="text-decoration: none;">Easy!Appointments</a>
|
||||
<a href="https://easyappointments.org" style="text-decoration: none;">Easy!Appointments</a>
|
||||
|
|
||||
<a href="$company_link" style="text-decoration: none;">$company_name</a>
|
||||
<a href="<?= $company_link ?>" style="text-decoration: none;"><?= $company_name ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
@ -52,27 +52,6 @@ class Email {
|
|||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the email template variables.
|
||||
*
|
||||
* This method finds and replaces the html variables of an email template. It is used to
|
||||
* generate dynamic HTML emails that are send as notifications to the system users.
|
||||
*
|
||||
* @param array $replaceArray Array that contains the variables to be replaced.
|
||||
* @param string $templateHtml The email template HTML.
|
||||
*
|
||||
* @return string Returns the new email html that contain the variables of the $replaceArray.
|
||||
*/
|
||||
protected function _replaceTemplateVariables(array $replaceArray, $templateHtml)
|
||||
{
|
||||
foreach ($replaceArray as $name => $value)
|
||||
{
|
||||
$templateHtml = str_replace($name, $value, $templateHtml);
|
||||
}
|
||||
|
||||
return $templateHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email with the appointment details.
|
||||
*
|
||||
|
@ -132,46 +111,30 @@ class Email {
|
|||
}
|
||||
|
||||
// Prepare template replace array.
|
||||
$replaceArray = [
|
||||
'$email_title' => $title->get(),
|
||||
'$email_message' => $message->get(),
|
||||
'$appointment_service' => $service['name'],
|
||||
'$appointment_provider' => $provider['first_name'] . ' ' . $provider['last_name'],
|
||||
'$appointment_start_date' => date($date_format . ' ' . $timeFormat, strtotime($appointment['start_datetime'])),
|
||||
'$appointment_end_date' => date($date_format . ' ' . $timeFormat, strtotime($appointment['end_datetime'])),
|
||||
'$appointment_link' => $appointmentLink->get(),
|
||||
'$company_link' => $company['company_link'],
|
||||
'$company_name' => $company['company_name'],
|
||||
'$customer_name' => $customer['first_name'] . ' ' . $customer['last_name'],
|
||||
'$customer_email' => $customer['email'],
|
||||
'$customer_phone' => $customer['phone_number'],
|
||||
'$customer_address' => $customer['address'],
|
||||
$email_title = $title->get();
|
||||
$email_message = $message->get();
|
||||
$appointment_service = $service['name'];
|
||||
$appointment_provider = $provider['first_name'] . ' ' . $provider['last_name'];
|
||||
$appointment_start_date = date($date_format . ' ' . $timeFormat, strtotime($appointment['start_datetime']));
|
||||
$appointment_end_date = date($date_format . ' ' . $timeFormat, strtotime($appointment['end_datetime']));
|
||||
$appointment_link = $appointmentLink->get();
|
||||
$company_link = $company['company_link'];
|
||||
$company_name = $company['company_name'];
|
||||
$customer_name = $customer['first_name'] . ' ' . $customer['last_name'];
|
||||
$customer_email = $customer['email'];
|
||||
$customer_phone = $customer['phone_number'];
|
||||
$customer_address = $customer['address'];
|
||||
|
||||
// Translations
|
||||
'Appointment Details' => $this->framework->lang->line('appointment_details_title'),
|
||||
'Service' => $this->framework->lang->line('service'),
|
||||
'Provider' => $this->framework->lang->line('provider'),
|
||||
'Start' => $this->framework->lang->line('start'),
|
||||
'End' => $this->framework->lang->line('end'),
|
||||
'Customer Details' => $this->framework->lang->line('customer_details_title'),
|
||||
'Name' => $this->framework->lang->line('name'),
|
||||
'Email' => $this->framework->lang->line('email'),
|
||||
'Phone' => $this->framework->lang->line('phone_number'),
|
||||
'Address' => $this->framework->lang->line('address'),
|
||||
'Appointment Link' => $this->framework->lang->line('appointment_link_title')
|
||||
];
|
||||
|
||||
$html = file_get_contents(__DIR__ . '/../../application/views/emails/appointment_details.php');
|
||||
$html = $this->_replaceTemplateVariables($replaceArray, $html);
|
||||
ob_start();
|
||||
require __DIR__ . '/../../application/views/emails/appointment_details.php';
|
||||
$html = ob_get_clean();
|
||||
|
||||
$mailer = $this->_createMailer();
|
||||
|
||||
$mailer->From = $company['company_email'];
|
||||
$mailer->FromName = $company['company_name'];
|
||||
$mailer->AddAddress($recipientEmail->get());
|
||||
$mailer->Subject = $title->get();
|
||||
$mailer->Body = $html;
|
||||
|
||||
$mailer->addStringAttachment($icsStream->get(), 'invitation.ics');
|
||||
|
||||
if ( ! $mailer->Send())
|
||||
|
@ -236,37 +199,21 @@ class Email {
|
|||
}
|
||||
|
||||
// Prepare email template data.
|
||||
$replaceArray = [
|
||||
'$email_title' => $this->framework->lang->line('appointment_cancelled_title'),
|
||||
'$email_message' => $this->framework->lang->line('appointment_removed_from_schedule'),
|
||||
'$appointment_service' => $service['name'],
|
||||
'$appointment_provider' => $provider['first_name'] . ' ' . $provider['last_name'],
|
||||
'$appointment_date' => date($date_format . ' ' . $timeFormat, strtotime($appointment['start_datetime'])),
|
||||
'$appointment_duration' => $service['duration'] . ' ' . $this->framework->lang->line('minutes'),
|
||||
'$company_link' => $company['company_link'],
|
||||
'$company_name' => $company['company_name'],
|
||||
'$customer_name' => $customer['first_name'] . ' ' . $customer['last_name'],
|
||||
'$customer_email' => $customer['email'],
|
||||
'$customer_phone' => $customer['phone_number'],
|
||||
'$customer_address' => $customer['address'],
|
||||
'$reason' => $reason->get(),
|
||||
$appointment_service = $service['name'];
|
||||
$appointment_provider = $provider['first_name'] . ' ' . $provider['last_name'];
|
||||
$appointment_date = date($date_format . ' ' . $timeFormat, strtotime($appointment['start_datetime']));
|
||||
$appointment_duration = $service['duration'] . ' ' . $this->framework->lang->line('minutes');
|
||||
$company_link = $company['company_link'];
|
||||
$company_name = $company['company_name'];
|
||||
$customer_name = $customer['first_name'] . ' ' . $customer['last_name'];
|
||||
$customer_email = $customer['email'];
|
||||
$customer_phone = $customer['phone_number'];
|
||||
$customer_address = $customer['address'];
|
||||
$reason = $reason->get();
|
||||
|
||||
// Translations
|
||||
'Appointment Details' => $this->framework->lang->line('appointment_details_title'),
|
||||
'Service' => $this->framework->lang->line('service'),
|
||||
'Provider' => $this->framework->lang->line('provider'),
|
||||
'Date' => $this->framework->lang->line('start'),
|
||||
'Duration' => $this->framework->lang->line('duration'),
|
||||
'Customer Details' => $this->framework->lang->line('customer_details_title'),
|
||||
'Name' => $this->framework->lang->line('name'),
|
||||
'Email' => $this->framework->lang->line('email'),
|
||||
'Phone' => $this->framework->lang->line('phone_number'),
|
||||
'Address' => $this->framework->lang->line('address'),
|
||||
'Reason' => $this->framework->lang->line('reason')
|
||||
];
|
||||
|
||||
$html = file_get_contents(__DIR__ . '/../../application/views/emails/delete_appointment.php');
|
||||
$html = $this->_replaceTemplateVariables($replaceArray, $html);
|
||||
ob_start();
|
||||
require __DIR__ . '/../../application/views/emails/delete_appointment.php';
|
||||
$html = ob_get_clean();
|
||||
|
||||
$mailer = $this->_createMailer();
|
||||
|
||||
|
@ -293,17 +240,16 @@ class Email {
|
|||
*/
|
||||
public function sendPassword(NonEmptyText $password, EmailAddress $recipientEmail, array $company)
|
||||
{
|
||||
$replaceArray = [
|
||||
'$email_title' => $this->framework->lang->line('new_account_password'),
|
||||
'$email_message' => $this->framework->lang->line('new_password_is'),
|
||||
'$company_name' => $company['company_name'],
|
||||
'$company_email' => $company['company_email'],
|
||||
'$company_link' => $company['company_link'],
|
||||
'$password' => '<strong>' . $password->get() . '</strong>'
|
||||
];
|
||||
$email_title = $this->framework->lang->line('new_account_password');
|
||||
$email_message = $this->framework->lang->line('new_password_is');
|
||||
$company_name = $company['company_name'];
|
||||
$company_email = $company['company_email'];
|
||||
$company_link = $company['company_link'];
|
||||
$password = '<strong>' . $password->get() . '</strong>';
|
||||
|
||||
$html = file_get_contents(__DIR__ . '/../../application/views/emails/new_password.php');
|
||||
$html = $this->_replaceTemplateVariables($replaceArray, $html);
|
||||
ob_start();
|
||||
require __DIR__ . '/../../application/views/emails/new_password.php';
|
||||
$html = ob_get_clean();
|
||||
|
||||
$mailer = $this->_createMailer();
|
||||
|
||||
|
|
Loading…
Reference in a new issue