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>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Appointment Details</title>
|
<title><?= lang('appointment_details_title') ?></title>
|
||||||
</head>
|
</head>
|
||||||
<body style="font: 13px arial, helvetica, tahoma;">
|
<body style="font: 13px arial, helvetica, tahoma;">
|
||||||
<div class="email-container" style="width: 650px; border: 1px solid #eee;">
|
<div class="email-container" style="width: 650px; border: 1px solid #eee;">
|
||||||
|
@ -8,63 +8,63 @@
|
||||||
height: 45px; padding: 10px 15px;">
|
height: 45px; padding: 10px 15px;">
|
||||||
<strong id="logo" style="color: white; font-size: 20px;
|
<strong id="logo" style="color: white; font-size: 20px;
|
||||||
text-shadow: 1px 1px 1px #8F8888; margin-top: 10px; display: inline-block">
|
text-shadow: 1px 1px 1px #8F8888; margin-top: 10px; display: inline-block">
|
||||||
$company_name</strong>
|
<?= $company_name ?></strong>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="content" style="padding: 10px 15px;">
|
<div id="content" style="padding: 10px 15px;">
|
||||||
<h2>$email_title</h2>
|
<h2><?= $email_title ?></h2>
|
||||||
<p>$email_message</p>
|
<p><?= $email_message ?></p>
|
||||||
|
|
||||||
<h2>Appointment Details</h2>
|
<h2><?= lang('appointment_details_title') ?></h2>
|
||||||
<table id="appointment-details">
|
<table id="appointment-details">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Service</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('service') ?></td>
|
||||||
<td style="padding: 3px;">$appointment_service</td>
|
<td style="padding: 3px;"><?= $appointment_service ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Provider</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('provider') ?></td>
|
||||||
<td style="padding: 3px;">$appointment_provider</td>
|
<td style="padding: 3px;"><?= $appointment_provider ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Start</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('start') ?></td>
|
||||||
<td style="padding: 3px;">$appointment_start_date</td>
|
<td style="padding: 3px;"><?= $appointment_start_date ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">End</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('end') ?></td>
|
||||||
<td style="padding: 3px;">$appointment_end_date</td>
|
<td style="padding: 3px;"><?= $appointment_end_date ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2>Customer Details</h2>
|
<h2><?= lang('customer_details_title') ?></h2>
|
||||||
<table id="customer-details">
|
<table id="customer-details">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Name</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('name') ?></td>
|
||||||
<td style="padding: 3px;">$customer_name</td>
|
<td style="padding: 3px;"><?= $customer_name ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Email</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('email') ?></td>
|
||||||
<td style="padding: 3px;">$customer_email</td>
|
<td style="padding: 3px;"><?= $customer_email ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Phone</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('phone_number') ?></td>
|
||||||
<td style="padding: 3px;">$customer_phone</td>
|
<td style="padding: 3px;"><?= $customer_phone ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Address</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('address') ?></td>
|
||||||
<td style="padding: 3px;">$customer_address</td>
|
<td style="padding: 3px;"><?= $customer_address ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2>Appointment Link</h2>
|
<h2><?= lang('appointment_link_title') ?></h2>
|
||||||
<a href="$appointment_link" style="width: 600px;">$appointment_link</a>
|
<a href="<?= $appointment_link ?>" style="width: 600px;"><?= $appointment_link ?></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="footer" style="padding: 10px; text-align: center; margin-top: 10px;
|
<div id="footer" style="padding: 10px; text-align: center; margin-top: 10px;
|
||||||
border-top: 1px solid #EEE; background: #FAFAFA;">
|
border-top: 1px solid #EEE; background: #FAFAFA;">
|
||||||
Powered by
|
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>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>$email_title</title>
|
<title><?= lang('appointment_cancelled_title') ?></title>
|
||||||
</head>
|
</head>
|
||||||
<body style="font: 13px arial, helvetica, tahoma;">
|
<body style="font: 13px arial, helvetica, tahoma;">
|
||||||
<div class="email-container" style="width: 650px; border: 1px solid #eee;">
|
<div class="email-container" style="width: 650px; border: 1px solid #eee;">
|
||||||
|
@ -8,63 +8,63 @@
|
||||||
height: 45px; padding: 10px 15px;">
|
height: 45px; padding: 10px 15px;">
|
||||||
<strong id="logo" style="color: white; font-size: 20px;
|
<strong id="logo" style="color: white; font-size: 20px;
|
||||||
text-shadow: 1px 1px 1px #8F8888; margin-top: 10px; display: inline-block">
|
text-shadow: 1px 1px 1px #8F8888; margin-top: 10px; display: inline-block">
|
||||||
$company_name</strong>
|
<?= $company_name ?></strong>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="content" style="padding: 10px 15px;">
|
<div id="content" style="padding: 10px 15px;">
|
||||||
<h2>$email_title</h2>
|
<h2><?= lang('appointment_cancelled_title') ?></h2>
|
||||||
<p>$email_message</p>
|
<p><?= lang('appointment_removed_from_schedule') ?></p>
|
||||||
|
|
||||||
<h2>Appointment Details</h2>
|
<h2><?= lang('appointment_details_title') ?></h2>
|
||||||
<table id="appointment-details">
|
<table id="appointment-details">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Service</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('service') ?></td>
|
||||||
<td style="padding: 3px;">$appointment_service</td>
|
<td style="padding: 3px;"><?= $appointment_service ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Provider</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('provider') ?></td>
|
||||||
<td style="padding: 3px;">$appointment_provider</td>
|
<td style="padding: 3px;"><?= $appointment_provider ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Date</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('start') ?></td>
|
||||||
<td style="padding: 3px;">$appointment_date</td>
|
<td style="padding: 3px;"><?= $appointment_date ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Duration</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('duration') ?></td>
|
||||||
<td style="padding: 3px;">$appointment_duration</td>
|
<td style="padding: 3px;"><?= $appointment_duration ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2>Customer Details</h2>
|
<h2><?= lang('customer_details_title') ?></h2>
|
||||||
<table id="customer-details">
|
<table id="customer-details">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Name</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('name') ?></td>
|
||||||
<td style="padding: 3px;">$customer_name</td>
|
<td style="padding: 3px;"><?= $customer_name ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Email</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('email') ?></td>
|
||||||
<td style="padding: 3px;">$customer_email</td>
|
<td style="padding: 3px;"><?= $customer_email ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Phone</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('phone_number') ?></td>
|
||||||
<td style="padding: 3px;">$customer_phone</td>
|
<td style="padding: 3px;"><?= $customer_phone ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="label" style="padding: 3px;font-weight: bold;">Address</td>
|
<td class="label" style="padding: 3px;font-weight: bold;"><?= lang('address') ?></td>
|
||||||
<td style="padding: 3px;">$customer_address</td>
|
<td style="padding: 3px;"><?= $customer_address ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2>Reason</h2>
|
<h2><?= lang('reason') ?></h2>
|
||||||
<p>$reason</p>
|
<p><?= $reason ?></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="footer" style="padding: 10px; text-align: center; margin-top: 10px;
|
<div id="footer" style="padding: 10px; text-align: center; margin-top: 10px;
|
||||||
border-top: 1px solid #EEE; background: #FAFAFA;">
|
border-top: 1px solid #EEE; background: #FAFAFA;">
|
||||||
Powered by
|
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>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -52,27 +52,6 @@ class Email {
|
||||||
$this->config = $config;
|
$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.
|
* Send an email with the appointment details.
|
||||||
*
|
*
|
||||||
|
@ -132,46 +111,30 @@ class Email {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare template replace array.
|
// Prepare template replace array.
|
||||||
$replaceArray = [
|
$email_title = $title->get();
|
||||||
'$email_title' => $title->get(),
|
$email_message = $message->get();
|
||||||
'$email_message' => $message->get(),
|
$appointment_service = $service['name'];
|
||||||
'$appointment_service' => $service['name'],
|
$appointment_provider = $provider['first_name'] . ' ' . $provider['last_name'];
|
||||||
'$appointment_provider' => $provider['first_name'] . ' ' . $provider['last_name'],
|
$appointment_start_date = date($date_format . ' ' . $timeFormat, strtotime($appointment['start_datetime']));
|
||||||
'$appointment_start_date' => date($date_format . ' ' . $timeFormat, strtotime($appointment['start_datetime'])),
|
$appointment_end_date = date($date_format . ' ' . $timeFormat, strtotime($appointment['end_datetime']));
|
||||||
'$appointment_end_date' => date($date_format . ' ' . $timeFormat, strtotime($appointment['end_datetime'])),
|
$appointment_link = $appointmentLink->get();
|
||||||
'$appointment_link' => $appointmentLink->get(),
|
$company_link = $company['company_link'];
|
||||||
'$company_link' => $company['company_link'],
|
$company_name = $company['company_name'];
|
||||||
'$company_name' => $company['company_name'],
|
$customer_name = $customer['first_name'] . ' ' . $customer['last_name'];
|
||||||
'$customer_name' => $customer['first_name'] . ' ' . $customer['last_name'],
|
$customer_email = $customer['email'];
|
||||||
'$customer_email' => $customer['email'],
|
$customer_phone = $customer['phone_number'];
|
||||||
'$customer_phone' => $customer['phone_number'],
|
$customer_address = $customer['address'];
|
||||||
'$customer_address' => $customer['address'],
|
|
||||||
|
|
||||||
// Translations
|
ob_start();
|
||||||
'Appointment Details' => $this->framework->lang->line('appointment_details_title'),
|
require __DIR__ . '/../../application/views/emails/appointment_details.php';
|
||||||
'Service' => $this->framework->lang->line('service'),
|
$html = ob_get_clean();
|
||||||
'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);
|
|
||||||
|
|
||||||
$mailer = $this->_createMailer();
|
$mailer = $this->_createMailer();
|
||||||
|
|
||||||
$mailer->From = $company['company_email'];
|
$mailer->From = $company['company_email'];
|
||||||
$mailer->FromName = $company['company_name'];
|
$mailer->FromName = $company['company_name'];
|
||||||
$mailer->AddAddress($recipientEmail->get());
|
$mailer->AddAddress($recipientEmail->get());
|
||||||
$mailer->Subject = $title->get();
|
$mailer->Subject = $title->get();
|
||||||
$mailer->Body = $html;
|
$mailer->Body = $html;
|
||||||
|
|
||||||
$mailer->addStringAttachment($icsStream->get(), 'invitation.ics');
|
$mailer->addStringAttachment($icsStream->get(), 'invitation.ics');
|
||||||
|
|
||||||
if ( ! $mailer->Send())
|
if ( ! $mailer->Send())
|
||||||
|
@ -236,37 +199,21 @@ class Email {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare email template data.
|
// Prepare email template data.
|
||||||
$replaceArray = [
|
$appointment_service = $service['name'];
|
||||||
'$email_title' => $this->framework->lang->line('appointment_cancelled_title'),
|
$appointment_provider = $provider['first_name'] . ' ' . $provider['last_name'];
|
||||||
'$email_message' => $this->framework->lang->line('appointment_removed_from_schedule'),
|
$appointment_date = date($date_format . ' ' . $timeFormat, strtotime($appointment['start_datetime']));
|
||||||
'$appointment_service' => $service['name'],
|
$appointment_duration = $service['duration'] . ' ' . $this->framework->lang->line('minutes');
|
||||||
'$appointment_provider' => $provider['first_name'] . ' ' . $provider['last_name'],
|
$company_link = $company['company_link'];
|
||||||
'$appointment_date' => date($date_format . ' ' . $timeFormat, strtotime($appointment['start_datetime'])),
|
$company_name = $company['company_name'];
|
||||||
'$appointment_duration' => $service['duration'] . ' ' . $this->framework->lang->line('minutes'),
|
$customer_name = $customer['first_name'] . ' ' . $customer['last_name'];
|
||||||
'$company_link' => $company['company_link'],
|
$customer_email = $customer['email'];
|
||||||
'$company_name' => $company['company_name'],
|
$customer_phone = $customer['phone_number'];
|
||||||
'$customer_name' => $customer['first_name'] . ' ' . $customer['last_name'],
|
$customer_address = $customer['address'];
|
||||||
'$customer_email' => $customer['email'],
|
$reason = $reason->get();
|
||||||
'$customer_phone' => $customer['phone_number'],
|
|
||||||
'$customer_address' => $customer['address'],
|
|
||||||
'$reason' => $reason->get(),
|
|
||||||
|
|
||||||
// Translations
|
ob_start();
|
||||||
'Appointment Details' => $this->framework->lang->line('appointment_details_title'),
|
require __DIR__ . '/../../application/views/emails/delete_appointment.php';
|
||||||
'Service' => $this->framework->lang->line('service'),
|
$html = ob_get_clean();
|
||||||
'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);
|
|
||||||
|
|
||||||
$mailer = $this->_createMailer();
|
$mailer = $this->_createMailer();
|
||||||
|
|
||||||
|
@ -293,17 +240,16 @@ class Email {
|
||||||
*/
|
*/
|
||||||
public function sendPassword(NonEmptyText $password, EmailAddress $recipientEmail, array $company)
|
public function sendPassword(NonEmptyText $password, EmailAddress $recipientEmail, array $company)
|
||||||
{
|
{
|
||||||
$replaceArray = [
|
$email_title = $this->framework->lang->line('new_account_password');
|
||||||
'$email_title' => $this->framework->lang->line('new_account_password'),
|
$email_message = $this->framework->lang->line('new_password_is');
|
||||||
'$email_message' => $this->framework->lang->line('new_password_is'),
|
$company_name = $company['company_name'];
|
||||||
'$company_name' => $company['company_name'],
|
$company_email = $company['company_email'];
|
||||||
'$company_email' => $company['company_email'],
|
$company_link = $company['company_link'];
|
||||||
'$company_link' => $company['company_link'],
|
$password = '<strong>' . $password->get() . '</strong>';
|
||||||
'$password' => '<strong>' . $password->get() . '</strong>'
|
|
||||||
];
|
|
||||||
|
|
||||||
$html = file_get_contents(__DIR__ . '/../../application/views/emails/new_password.php');
|
ob_start();
|
||||||
$html = $this->_replaceTemplateVariables($replaceArray, $html);
|
require __DIR__ . '/../../application/views/emails/new_password.php';
|
||||||
|
$html = ob_get_clean();
|
||||||
|
|
||||||
$mailer = $this->_createMailer();
|
$mailer = $this->_createMailer();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue