Files
itflow/agent/includes/bulk_email_fields.php

115 lines
6.1 KiB
PHP

<?php
/*
* The fields of an email to many contacts - Email on the contacts and clients
* lists (modals/contact/contact_bulk_email.php, modals/client/client_bulk_email.php):
* the mailbox it comes from, the name it shows, the subject, the message, a
* greeting, and when to send it. They post what emailBulkSend() takes
* (functions/email.php) - the email goes out in the email look, with the
* logo and the company's details, and a link to unsubscribe. Under From,
* where its bounces go (mailQueueBouncesTo()); Send at is on the agent's
* own clock (functions/user_timezone.php).
*
* Should not be accessed directly.
*/
isset($mysqli) || die("Direct file access is not allowed");
$bulk_mailboxes = emailMailboxes();
$bulk_bounces = [];
foreach ($bulk_mailboxes as $key => $box) {
$bulk_bounces[$key] = mailQueueBouncesTo($box['email']);
}
$bulk_reads = (string) ($config_imap_username ?? '');
?>
<?php if (!emailReady()) { ?>
<div class="alert alert-warning mb-3">
<i class="fas fa-fw fa-exclamation-triangle me-2"></i>Outgoing mail isn't set up, so nothing can be sent yet<?= $session_is_admin ? ' - set it up in <a href="/admin/settings_mail.php" class="alert-link">Admin &gt; Mail</a>' : '' ?>.
</div>
<?php } ?>
<div class="row g-3">
<div class="col-sm-6">
<label class="form-label">From</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-inbox"></i></span>
<select class="form-select" name="mailbox" required>
<?php foreach ($bulk_mailboxes as $key => $box) { ?>
<option value="<?= $key ?>" data-name="<?= escapeHtml($box['name']) ?>" data-bounces="<?= escapeHtml($bulk_bounces[$key]['address']) ?>" data-bounces-read="<?= $bulk_bounces[$key]['read'] ? 1 : 0 ?>"><?= escapeHtml($box['label'] . ' - ' . $box['email']) ?></option>
<?php } ?>
</select>
</div>
<!-- Where its bounces go - read, they mark their contacts Email bounced (functions/mail_queue.php, mailQueueReturnPath()) -->
<div class="form-text" data-bulk-bounces-read hidden>Bounces come back to <span data-bulk-bounces-to></span>, where ITFlow marks the contacts Email bounced.</div>
<div class="form-text" data-bulk-bounces-unread hidden>Bounces go to <span data-bulk-bounces-to></span>, which ITFlow doesn't read<?= $config_ticket_email_parse && filter_var($bulk_reads, FILTER_VALIDATE_EMAIL) ? ' - from ' . escapeHtml($bulk_reads) . ', they would be' : '' ?>.</div>
</div>
<div class="col-sm-6">
<label class="form-label">Name it shows</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-signature"></i></span>
<input type="text" class="form-control" name="mail_from_name" maxlength="255" placeholder="The mailbox's own name"
value="<?= escapeHtml((string) (reset($bulk_mailboxes)['name'] ?? '')) ?>">
</div>
</div>
<div class="col-12">
<label class="form-label">Subject <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-heading"></i></span>
<input type="text" class="form-control" name="subject" placeholder="Subject" maxlength="255" required>
</div>
</div>
<div class="col-12">
<label class="form-label">Message <strong class="text-danger">*</strong></label>
<textarea class="form-control tinymce" name="body" placeholder="Type an email in here"></textarea>
<div class="form-text">It goes out in your email look - your logo above it, your company's details below, and a line under it saying why they got it.</div>
</div>
<div class="col-sm-6">
<div class="form-check mt-sm-4">
<input type="checkbox" class="form-check-input" name="greet" value="1" id="bulkEmailGreet">
<label class="form-check-label" for="bulkEmailGreet">Start it "Hello" and their name</label>
</div>
</div>
<div class="col-sm-6">
<label class="form-label">Send at</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-calendar"></i></span>
<input type="datetime-local" class="form-control" name="queued_at" min="<?= escapeHtml(substr(timezoneNow(), 0, 16)) ?>">
</div>
<div class="form-text">Leave it empty to send now.</div>
<?= timezoneFormHint() ?>
</div>
<div class="col-12">
<div class="form-text mt-0"><i class="fas fa-fw fa-info-circle me-1"></i>Contacts marked Email bounced, and those who unsubscribed, are left out. Each email has a link to unsubscribe from email like this - ticket emails and invoices still go.</div>
</div>
</div>
<script>
itflowReady(function () {
// The name follows the mailbox, until it is typed over - and the line under it says where its bounces go
document.querySelectorAll('select[name="mailbox"]').forEach(function (select) {
var form = select.closest('form');
var name = form.querySelector('input[name="mail_from_name"]');
var last = name.value;
var bounces = function () {
var option = select.options[select.selectedIndex];
var read = option && option.getAttribute('data-bounces-read') === '1';
form.querySelector('[data-bulk-bounces-read]').hidden = !option || !read;
form.querySelector('[data-bulk-bounces-unread]').hidden = !option || read;
form.querySelectorAll('[data-bulk-bounces-to]').forEach(function (to) {
to.textContent = option ? option.getAttribute('data-bounces') : '';
});
};
bounces();
select.addEventListener('change', function () {
var picked = select.options[select.selectedIndex].getAttribute('data-name') || '';
if (name.value === last) {
name.value = picked;
}
last = picked;
bounces();
});
});
});
</script>