Render email metadata as real tables and redesign the shell
Metadata blocks were divs styled with display:table. Nested blocks and orphan cells created phantom columns that squeezed the value column to a character or two. Every metadata block is now a real <table>/<tr>/<td>, which mail clients lay out reliably, and the value column always fills the remaining width. The shared shell gets a gradient hero header, timestamp pill, dark frame, and refreshed section, card, and code-block styling.
This commit is contained in:
+73
-68
@@ -31,26 +31,26 @@ function renderDataAsTable($data, $depth = 0) {
|
||||
if (is_array($item)) {
|
||||
$html .= '<div class="array-item">';
|
||||
$html .= '<div class="array-item-title">Item ' . ($index + 1) . '</div>';
|
||||
$html .= '<div class="metadata">';
|
||||
$html .= '<table class="metadata" role="presentation" cellspacing="0" cellpadding="0" width="100%">';
|
||||
foreach ($item as $key => $value) {
|
||||
$keySafe = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
if (is_array($value)) {
|
||||
$html .= '<div class="metadata-row">';
|
||||
$html .= '<div class="metadata-label">' . $keySafe . '</div>';
|
||||
$html .= '<div class="metadata-value">';
|
||||
$html .= '<tr>';
|
||||
$html .= '<td class="metadata-label">' . $keySafe . '</td>';
|
||||
$html .= '<td class="metadata-value">';
|
||||
$html .= renderDataAsTable($value, $depth + 1);
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '</td>';
|
||||
$html .= '</tr>';
|
||||
} else {
|
||||
$valueSafe = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
|
||||
$html .= '<div class="metadata-row">';
|
||||
$html .= '<div class="metadata-label">' . $keySafe . '</div>';
|
||||
$html .= '<div class="metadata-value">' . $valueSafe . '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '<tr>';
|
||||
$html .= '<td class="metadata-label">' . $keySafe . '</td>';
|
||||
$html .= '<td class="metadata-value">' . $valueSafe . '</td>';
|
||||
$html .= '</tr>';
|
||||
}
|
||||
}
|
||||
$html .= '</div>';
|
||||
$html .= '</table>';
|
||||
$html .= '</div>';
|
||||
} else {
|
||||
$valueSafe = htmlspecialchars((string)$item, ENT_QUOTES, 'UTF-8');
|
||||
@@ -59,32 +59,32 @@ function renderDataAsTable($data, $depth = 0) {
|
||||
}
|
||||
} else {
|
||||
// Render as key-value table
|
||||
$html .= '<div class="metadata">';
|
||||
$html .= '<table class="metadata" role="presentation" cellspacing="0" cellpadding="0" width="100%">';
|
||||
foreach ($data as $key => $value) {
|
||||
$keySafe = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
if (is_array($value) && !empty($value)) {
|
||||
// Close current table and start a subsection
|
||||
$html .= '</div>';
|
||||
$html .= '</table>';
|
||||
$html .= '<div class="subsection">';
|
||||
$html .= '<div class="subsection-title">' . $keySafe . '</div>';
|
||||
$html .= renderDataAsTable($value, $depth + 1);
|
||||
$html .= '</div>';
|
||||
$html .= '<div class="metadata">';
|
||||
$html .= '<table class="metadata" role="presentation" cellspacing="0" cellpadding="0" width="100%">';
|
||||
} else if (is_array($value) && empty($value)) {
|
||||
$html .= '<div class="metadata-row">';
|
||||
$html .= '<div class="metadata-label">' . $keySafe . '</div>';
|
||||
$html .= '<div class="metadata-value"><em>empty</em></div>';
|
||||
$html .= '</div>';
|
||||
$html .= '<tr>';
|
||||
$html .= '<td class="metadata-label">' . $keySafe . '</td>';
|
||||
$html .= '<td class="metadata-value"><em>empty</em></td>';
|
||||
$html .= '</tr>';
|
||||
} else {
|
||||
$valueSafe = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
|
||||
$html .= '<div class="metadata-row">';
|
||||
$html .= '<div class="metadata-label">' . $keySafe . '</div>';
|
||||
$html .= '<div class="metadata-value">' . $valueSafe . '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '<tr>';
|
||||
$html .= '<td class="metadata-label">' . $keySafe . '</td>';
|
||||
$html .= '<td class="metadata-value">' . $valueSafe . '</td>';
|
||||
$html .= '</tr>';
|
||||
}
|
||||
}
|
||||
$html .= '</div>';
|
||||
$html .= '</table>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
@@ -102,6 +102,8 @@ function renderDataAsTable($data, $depth = 0) {
|
||||
function emailShell($title, $stamp, $body, $footer = 'Automatically forwarded to your inbox.') {
|
||||
$host = htmlspecialchars($_SERVER['HTTP_HOST'] ?? 'webhook', ENT_QUOTES, 'UTF-8');
|
||||
$plainTitle = strip_tags($title);
|
||||
$mono = "ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace";
|
||||
$sans = "-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif";
|
||||
return <<<HTML
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-GB">
|
||||
@@ -109,57 +111,60 @@ function emailShell($title, $stamp, $body, $footer = 'Automatically forwarded to
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="color-scheme" content="light">
|
||||
<meta name="supported-color-schemes" content="light">
|
||||
<title>$plainTitle</title>
|
||||
<style>
|
||||
body { margin:0; padding:0; background:#f3f1fb; color:#15151f; -webkit-font-smoothing:antialiased;
|
||||
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif; font-size:15px; line-height:1.6; }
|
||||
body { margin:0; padding:0; background:#0f0f17; color:#15151f; -webkit-font-smoothing:antialiased; font-family:$sans; font-size:15px; line-height:1.6; }
|
||||
a { color:#7c3aed; }
|
||||
.wrap { padding:28px 12px; }
|
||||
.container { max-width:640px; margin:0 auto; background:#ffffff; border-radius:16px; overflow:hidden;
|
||||
box-shadow:0 12px 40px rgba(40,20,90,.10); border:1px solid #e9e6f5; }
|
||||
.stripe { height:6px; background:#8b5cf6; background-image:linear-gradient(90deg,#8b5cf6,#ec4899 55%,#f97316); }
|
||||
.header { padding:28px 32px 20px; border-bottom:1px solid #eeecf6; }
|
||||
.header h1 { margin:0 0 6px; font-size:22px; font-weight:800; letter-spacing:-.02em; line-height:1.25; color:#15151f; }
|
||||
.timestamp { margin:0; font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:12px; color:#8b8ba3; letter-spacing:.06em; text-transform:uppercase; }
|
||||
.section { padding:22px 32px 0; }
|
||||
.section-title { font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:11px; font-weight:700; letter-spacing:.14em; text-transform:uppercase; color:#7c3aed; margin:0 0 10px; }
|
||||
.subsection { margin:14px 0; }
|
||||
.subsection-title { font-size:13px; font-weight:700; color:#15151f; margin:16px 0 8px; padding-left:10px; border-left:3px solid #ec4899; }
|
||||
.metadata { display:table; width:100%; border:1px solid #e9e6f5; border-radius:10px; border-collapse:separate; overflow:hidden; }
|
||||
.metadata-row { display:table-row; }
|
||||
.metadata-label, .metadata-value { display:table-cell; padding:10px 14px; border-bottom:1px solid #f0eef8; vertical-align:top; }
|
||||
.metadata-row:last-child .metadata-label, .metadata-row:last-child .metadata-value { border-bottom:0; }
|
||||
.metadata-label { width:150px; font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:12px; color:#6b6b80; background:#faf9fe; white-space:nowrap; }
|
||||
.metadata-value { font-size:14px; color:#15151f; word-break:break-word; }
|
||||
.data-box { margin:0; padding:16px 18px; background:#0f0f17; color:#e6e6f0; border-radius:10px; font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
|
||||
font-size:12.5px; line-height:1.65; white-space:pre-wrap; word-break:break-word; overflow-x:auto; }
|
||||
.path-title { margin:18px 0 8px; padding:8px 12px; font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:12px; font-weight:700;
|
||||
color:#db2777; background:#fdf2f8; border-left:3px solid #ec4899; border-radius:0 8px 8px 0; }
|
||||
.array-item, .array-item-simple { margin:0 0 12px; padding:14px 16px; background:#faf9fe; border:1px solid #e9e6f5; border-radius:10px; }
|
||||
.array-item-title { font-size:13px; font-weight:700; margin:0 0 10px; color:#15151f; }
|
||||
.array-item .metadata { background:#fff; }
|
||||
.message-box { margin:12px 0; padding:14px 16px; background:#faf9fe; border:1px solid #e9e6f5; border-radius:10px; font-size:15px; line-height:1.6; }
|
||||
.error-box { margin:12px 0; padding:12px 14px; background:#fef2f2; border-left:3px solid #ef4444; border-radius:0 8px 8px 0; }
|
||||
.footer { margin-top:28px; padding:18px 32px 24px; border-top:1px solid #eeecf6; text-align:center; color:#8b8ba3;
|
||||
font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:11px; letter-spacing:.04em; }
|
||||
.footer p { margin:0 0 4px; }
|
||||
table { border-collapse:separate; border-spacing:0; }
|
||||
.frame { width:100%; max-width:660px; }
|
||||
.hero { background:#7c3aed; background-image:linear-gradient(120deg,#8b5cf6 0%,#ec4899 55%,#f97316 100%); padding:32px 34px 28px; border-radius:20px 20px 0 0; }
|
||||
.kicker { font-family:$mono; font-size:11px; letter-spacing:.18em; text-transform:uppercase; color:rgba(255,255,255,.75); margin:0 0 10px; }
|
||||
.hero h1 { margin:0 0 14px; font-size:26px; font-weight:800; letter-spacing:-.02em; line-height:1.2; color:#ffffff; }
|
||||
.stamp { display:inline-block; font-family:$mono; font-size:12px; letter-spacing:.06em; color:#ffffff; background:rgba(15,15,23,.28); padding:6px 12px; border-radius:999px; }
|
||||
.card { background:#ffffff; padding:8px 0 14px; border-radius:0 0 20px 20px; }
|
||||
.section { padding:24px 34px 0; }
|
||||
.section-title { font-family:$mono; font-size:11px; font-weight:700; letter-spacing:.16em; text-transform:uppercase; color:#7c3aed; margin:0 0 12px; padding-left:10px; border-left:3px solid #ec4899; line-height:1.4; }
|
||||
.subsection { margin:14px 0 0; }
|
||||
.subsection-title { font-size:13px; font-weight:700; color:#15151f; margin:16px 0 8px; }
|
||||
table.metadata { width:100%; border:1px solid #e6e3f2; border-radius:12px; overflow:hidden; background:#ffffff; }
|
||||
td.metadata-label, td.metadata-value { padding:11px 14px; border-bottom:1px solid #efedf7; vertical-align:top; text-align:left; }
|
||||
tr:last-child > td.metadata-label, tr:last-child > td.metadata-value { border-bottom:0; }
|
||||
td.metadata-label { width:150px; max-width:170px; font-family:$mono; font-size:12px; line-height:1.5; color:#6b6b80; background:#f8f7fd; word-break:break-word; }
|
||||
td.metadata-value { font-size:14px; color:#15151f; word-break:break-word; }
|
||||
td.metadata-value table.metadata { margin:2px 0; }
|
||||
.data-box { margin:0; padding:16px 18px; background:#15151f; color:#e6e6f0; border-radius:12px; border:1px solid #2a2a3a; font-family:$mono; font-size:12.5px; line-height:1.65; white-space:pre-wrap; word-break:break-word; overflow-x:auto; }
|
||||
.path-title { display:inline-block; margin:18px 0 8px; padding:5px 12px; font-family:$mono; font-size:12px; font-weight:700; color:#be185d; background:#fdf2f8; border:1px solid #fbcfe8; border-radius:999px; }
|
||||
.array-item { margin:0 0 12px; padding:16px; background:#f8f7fd; border:1px solid #e6e3f2; border-radius:14px; }
|
||||
.array-item-title { font-size:14px; font-weight:800; margin:0 0 10px; color:#15151f; letter-spacing:-.01em; }
|
||||
.array-item-simple { margin:0 0 6px; padding:9px 14px; background:#f8f7fd; border:1px solid #e6e3f2; border-radius:10px; font-size:14px; }
|
||||
.simple-value { font-size:14px; padding:4px 0; }
|
||||
.message-box { margin:12px 0; padding:16px 18px 16px 20px; background:#f8f7fd; border-left:4px solid #8b5cf6; border-radius:0 12px 12px 0; font-size:16px; line-height:1.55; color:#15151f; }
|
||||
.error-box { margin:12px 0; padding:12px 14px; background:#fef2f2; border-left:4px solid #ef4444; border-radius:0 10px 10px 0; }
|
||||
.footer { padding:22px 34px 8px; text-align:center; color:#6a6a86; font-family:$mono; font-size:11px; letter-spacing:.06em; line-height:1.8; }
|
||||
.footer a { color:#a78bfa; text-decoration:none; }
|
||||
.footer .bolt { color:#f97316; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<div class="container">
|
||||
<div class="stripe"></div>
|
||||
<div class="header">
|
||||
<h1>$title</h1>
|
||||
<p class="timestamp">$stamp</p>
|
||||
</div>
|
||||
<body style="margin:0;padding:0;background:#0f0f17;">
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#0f0f17;">
|
||||
<tr><td align="center" style="padding:36px 12px 28px;">
|
||||
<table role="presentation" class="frame" cellpadding="0" cellspacing="0">
|
||||
<tr><td class="hero">
|
||||
<p class="kicker">Webhook › $host</p>
|
||||
<h1>$title</h1>
|
||||
<span class="stamp">$stamp</span>
|
||||
</td></tr>
|
||||
<tr><td class="card">
|
||||
$body
|
||||
<div class="footer">
|
||||
<p>$footer</p>
|
||||
<p>⚡ $host</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td></tr>
|
||||
<tr><td class="footer">
|
||||
$footer<br>
|
||||
<span class="bolt">⚡</span> <a href="https://$host/">$host</a>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
Reference in New Issue
Block a user