feat(mailing): Kundenrundmail mit Empfängern aus Buchungen, Abmeldelink und Versandprotokoll
Empfänger kommen aus bookings.email (dedupliziert, ohne Abmeldungen), Text mit
{jahr}, Testmail an die eigene Adresse, Versand in Häppchen über mail_send().
Abmeldungen landen in mail_optouts und gelten für alle künftigen Rundmails.
Migration 009_mailing.sql, DSGVO-Verzeichnis und ROADMAP (Feature 18) ergänzt.
This commit is contained in:
parent
1adc3c8f33
commit
5cce6ca86f
11 changed files with 657 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ $items = [
|
|||
'/admin/users' => ['label' => 'Benutzer', 'icon' => 'i-user'],
|
||||
'/admin/employees' => ['label' => 'Mitarbeiter', 'icon' => 'i-users'],
|
||||
'/admin/trailers' => ['label' => 'Anhänger', 'icon' => 'i-truck'],
|
||||
'/admin/mailings' => ['label' => 'Rundmail', 'icon' => 'i-mail'],
|
||||
];
|
||||
?>
|
||||
<nav class="admin-nav" aria-label="Verwaltung">
|
||||
|
|
|
|||
154
views/admin_mailings.php
Normal file
154
views/admin_mailings.php
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
<?php
|
||||
/** @var list<array{email: string, bookings: int, last_booking: ?string}> $recipients */
|
||||
/** @var int $optoutCount */
|
||||
/** @var list<array<string, mixed>> $mailings */
|
||||
/** @var array{subject: string, body: string} $values */
|
||||
/** @var array<string, string> $errors */
|
||||
/** @var bool $mailEnabled */
|
||||
/** @var int $batchSize */
|
||||
$errorFor = static fn (string $key): string => (string) ($errors[$key] ?? '');
|
||||
$lastBooking = $recipients ? (string) ($recipients[count($recipients) - 1]['last_booking'] ?? '') : '';
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Verwaltung</p>
|
||||
<h1>Kundenrundmail</h1>
|
||||
<p class="page-head__lede">Dankeschön oder Saisonhinweis an alle Kunden, die gebucht haben.
|
||||
Die Adressen kommen aus den Buchungen – gepflegt wird nichts doppelt. Text mit
|
||||
<code>{jahr}</code> setzt automatisch das laufende Jahr ein.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require __DIR__ . '/_admin_nav.php'; ?>
|
||||
|
||||
<?php if (!$mailEnabled): ?>
|
||||
<div class="alert alert--warning" role="status">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Mailversand ist ausgeschaltet.</strong>
|
||||
<p>In der Konfiguration steht <code>app.mail_enabled</code> auf aus. Anlegen und Testen ist
|
||||
möglich, der Versand an Kunden nicht.</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2>Empfänger</h2>
|
||||
<p><?= count($recipients) ?> Kunden mit gültiger Adresse in einer Buchung<?= $lastBooking !== '' ? ', letzte Buchung am ' . e(date('d.m.Y', strtotime($lastBooking))) : '' ?>.</p>
|
||||
</div>
|
||||
<div class="panel__actions">
|
||||
<span class="muted small"><?= $optoutCount ?> abgemeldet</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="muted small">Abgemeldete Adressen werden automatisch übersprungen. Jede Mail enthält einen
|
||||
Abmeldelink; Buchungsbestätigungen und Erinnerungen bleiben davon unberührt.</p>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2>Neue Rundmail</h2>
|
||||
<p>Erst als Testmail an die eigene Adresse schicken, dann anlegen. Der Versand läuft danach in
|
||||
Häppchen von <?= (int) $batchSize ?> Mails.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($errors): ?>
|
||||
<div class="alert alert--error" role="alert">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Bitte die markierten Felder prüfen.</strong>
|
||||
<?php foreach ($errors as $message): ?><p><?= e($message) ?></p><?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="<?= e(url('/admin/mailings')) ?>" class="form-grid form-grid--single">
|
||||
<?= csrf_field() ?>
|
||||
<label class="field<?= $errorFor('subject') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Betreff</span>
|
||||
<input type="text" name="subject" value="<?= e($values['subject']) ?>" maxlength="190" required
|
||||
placeholder="Zum Jahresende: vielen Dank für Ihr Vertrauen in {jahr}">
|
||||
<?php if ($errorFor('subject')): ?><em class="field-error"><?= e($errorFor('subject')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
|
||||
<label class="field<?= $errorFor('body') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Text</span>
|
||||
<textarea name="body" rows="10" maxlength="5000" required
|
||||
placeholder="Hallo liebe Kundin, hallo lieber Kunde, wir sagen Danke für {jahr} …"><?= e($values['body']) ?></textarea>
|
||||
<?php if ($errorFor('body')): ?><em class="field-error"><?= e($errorFor('body')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
|
||||
<p class="muted small">Abschließend setzt das System automatisch den Satz „Sie erhalten diese
|
||||
Nachricht, weil Sie bei Drink it cold einen Kühlanhänger gebucht haben.“ und den Abmeldelink
|
||||
darunter.</p>
|
||||
|
||||
<div class="btn-row">
|
||||
<button type="submit" name="action" value="test" class="btn">Testmail an mich</button>
|
||||
<button type="submit" name="action" value="create" class="btn primary">An <?= count($recipients) ?> Kunden anlegen</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2>Bisherige Rundmails</h2>
|
||||
<p>Der Stand je Empfänger steht im Protokoll; „Weiter senden“ schickt die nächste Häppchen-Größe.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!$mailings): ?>
|
||||
<p class="muted">Noch keine Rundmail angelegt.</p>
|
||||
<?php else: ?>
|
||||
<div class="table-wrap">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Angelegt</th>
|
||||
<th scope="col">Betreff</th>
|
||||
<th scope="col">Empfänger</th>
|
||||
<th scope="col">Stand</th>
|
||||
<th scope="col">Aktion</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($mailings as $mailing): ?>
|
||||
<?php
|
||||
$pending = (int) $mailing['pending'];
|
||||
$sent = (int) $mailing['sent_count'];
|
||||
$failed = (int) $mailing['failed_count'];
|
||||
$total = (int) $mailing['recipient_count'];
|
||||
?>
|
||||
<tr>
|
||||
<td><?= e(date('d.m.Y H:i', strtotime((string) $mailing['created_at']))) ?></td>
|
||||
<td><?= e((string) $mailing['subject']) ?></td>
|
||||
<td><?= $total ?></td>
|
||||
<td>
|
||||
<?= $sent ?> versendet<?= $failed > 0 ? ', ' . $failed . ' fehlgeschlagen' : '' ?>
|
||||
<?= $pending > 0 ? ' · ' . $pending . ' offen' : ' · fertig' ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($pending > 0): ?>
|
||||
<form method="post" action="<?= e(url('/admin/mailings')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="action" value="send">
|
||||
<input type="hidden" name="mailing_id" value="<?= (int) $mailing['id'] ?>">
|
||||
<input type="hidden" name="batch" value="<?= (int) $batchSize ?>">
|
||||
<button type="submit" class="btn small primary"<?= $mailEnabled ? '' : ' disabled' ?>>
|
||||
<?= $pending > (int) $batchSize
|
||||
? 'Nächste ' . (int) $batchSize . ' senden'
|
||||
: 'Rest (' . $pending . ') senden' ?>
|
||||
</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<span class="muted small">abgeschlossen</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
56
views/mailing_abmelden.php
Normal file
56
views/mailing_abmelden.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* Abmeldeseite für die Kundenrundmail (/abmelden?e=…&t=…).
|
||||
* Bewusst ohne App-Navigation: Empfänger sind Kunden, keine Mitarbeiter.
|
||||
* Der Link führt erst auf eine Bestätigung, damit Vorschau- und
|
||||
* Sicherheitsscanner in Mailprogrammen niemanden versehentlich abmelden.
|
||||
*
|
||||
* @var string $email
|
||||
* @var string $token
|
||||
* @var bool $valid
|
||||
* @var bool $done
|
||||
* @var bool $already
|
||||
* @var string $error
|
||||
*/
|
||||
$base = rtrim((string) config('app.public_url', ''), '/');
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex, nofollow, noarchive">
|
||||
<title>Rundmail abbestellen · Drink it cold</title>
|
||||
<link rel="stylesheet" href="<?= e(asset('app.css')) ?>">
|
||||
</head>
|
||||
<body class="legal-page">
|
||||
<main class="legal">
|
||||
<h1>Rundmail abbestellen</h1>
|
||||
|
||||
<?php if ($done): ?>
|
||||
<p><strong>Erledigt.</strong> Die Adresse <em><?= e($email) ?></em> ist aus der Empfängerliste
|
||||
für Rundmails entfernt. Um Buchungen, Rechnungen und Terminbestätigungen kümmern wir uns
|
||||
unverändert.</p>
|
||||
<?php elseif ($error !== ''): ?>
|
||||
<p><strong><?= e($error) ?></strong> Bitte den Link aus der E-Mail erneut öffnen.</p>
|
||||
<?php elseif (!$valid): ?>
|
||||
<p>Dieser Abmeldelink ist ungültig oder unvollständig. Bitte den Link aus der E-Mail
|
||||
vollständig kopieren.</p>
|
||||
<?php elseif ($already): ?>
|
||||
<p>Die Adresse <em><?= e($email) ?></em> erhält bereits keine Rundmails mehr.</p>
|
||||
<?php else: ?>
|
||||
<p>Soll die Adresse <em><?= e($email) ?></em> künftig keine Rundmails (zum Beispiel das
|
||||
Dankeschön zum Jahresende) mehr erhalten?</p>
|
||||
<form method="post" action="<?= e(url('/abmelden')) ?>" class="btn-row">
|
||||
<input type="hidden" name="e" value="<?= e($email) ?>">
|
||||
<input type="hidden" name="t" value="<?= e($token) ?>">
|
||||
<button type="submit" class="btn">Ja, Rundmails abbestellen</button>
|
||||
</form>
|
||||
<p class="muted small">Bestätigungen und Erinnerungen zu gebuchten Terminen sind davon nicht
|
||||
betroffen.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="muted small"><a href="<?= e($base . '/') ?>">Zurück zur Startseite</a></p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue