This commit is contained in:
2026-03-28 21:16:21 +01:00
parent 572643ad82
commit cbc2058b83
15 changed files with 767 additions and 277 deletions

View File

@@ -63,6 +63,7 @@ final class EmailSendingService
$variableMap = $this->variableResolver->buildVariableMap($order, $addresses, $companySettings);
$resolvedSubject = $this->variableResolver->resolve((string) ($template['subject'] ?? ''), $variableMap);
$resolvedBody = $this->variableResolver->resolve((string) ($template['body_html'] ?? ''), $variableMap);
$resolvedBody = $this->composeBody($resolvedBody, $mailbox, $variableMap);
$attachments = [];
$attachmentType = (string) ($template['attachment_1'] ?? '');
@@ -142,6 +143,9 @@ final class EmailSendingService
$resolvedSubject = $this->variableResolver->resolve((string) ($template['subject'] ?? ''), $variableMap);
$resolvedBody = $this->variableResolver->resolve((string) ($template['body_html'] ?? ''), $variableMap);
$mailbox = $this->resolveMailbox(null, $template);
$resolvedBody = $this->composeBody($resolvedBody, $mailbox, $variableMap);
$attachmentNames = [];
$attachmentType = (string) ($template['attachment_1'] ?? '');
if ($attachmentType !== '') {
@@ -158,6 +162,38 @@ final class EmailSendingService
];
}
/**
* @param array<string, mixed>|null $mailbox
* @param array<string, string> $variableMap
*/
private function composeBody(string $resolvedBody, ?array $mailbox, array $variableMap): string
{
if ($mailbox === null) {
return $resolvedBody;
}
$header = trim((string) ($mailbox['header_html'] ?? ''));
$footer = trim((string) ($mailbox['footer_html'] ?? ''));
if ($header !== '') {
$header = $this->variableResolver->resolve($header, $variableMap);
}
if ($footer !== '') {
$footer = $this->variableResolver->resolve($footer, $variableMap);
}
$parts = [];
if ($header !== '') {
$parts[] = $header;
}
$parts[] = $resolvedBody;
if ($footer !== '') {
$parts[] = $footer;
}
return implode("\n", $parts);
}
/**
* @param array<string, mixed>|null $template
* @return array<string, mixed>|null

View File

@@ -88,6 +88,8 @@ final class EmailMailboxController
'smtp_password' => $password,
'sender_email' => $senderEmail,
'sender_name' => $request->input('sender_name', ''),
'header_html' => $request->input('header_html', ''),
'footer_html' => $request->input('footer_html', ''),
'is_default' => $request->input('is_default', null),
'is_active' => $request->input('is_active', null),
]);

View File

@@ -84,6 +84,9 @@ final class EmailMailboxRepository
$this->pdo->prepare('UPDATE email_mailboxes SET is_default = 0 WHERE is_default = 1')->execute();
}
$headerHtml = isset($data['header_html']) && trim((string) $data['header_html']) !== '' ? trim((string) $data['header_html']) : null;
$footerHtml = isset($data['footer_html']) && trim((string) $data['footer_html']) !== '' ? trim((string) $data['footer_html']) : null;
$params = [
'name' => trim((string) ($data['name'] ?? '')),
'smtp_host' => trim((string) ($data['smtp_host'] ?? '')),
@@ -92,6 +95,8 @@ final class EmailMailboxRepository
'smtp_username' => trim((string) ($data['smtp_username'] ?? '')),
'sender_email' => trim((string) ($data['sender_email'] ?? '')),
'sender_name' => trim((string) ($data['sender_name'] ?? '')) ?: null,
'header_html' => $headerHtml,
'footer_html' => $footerHtml,
'is_default' => $isDefault,
'is_active' => isset($data['is_active']) ? 1 : 0,
];
@@ -110,6 +115,8 @@ final class EmailMailboxRepository
'smtp_username = :smtp_username',
'sender_email = :sender_email',
'sender_name = :sender_name',
'header_html = :header_html',
'footer_html = :footer_html',
'is_default = :is_default',
'is_active = :is_active',
];
@@ -128,8 +135,8 @@ final class EmailMailboxRepository
}
$statement = $this->pdo->prepare(
'INSERT INTO email_mailboxes (name, smtp_host, smtp_port, smtp_encryption, smtp_username, smtp_password_encrypted, sender_email, sender_name, is_default, is_active)
VALUES (:name, :smtp_host, :smtp_port, :smtp_encryption, :smtp_username, :smtp_password_encrypted, :sender_email, :sender_name, :is_default, :is_active)'
'INSERT INTO email_mailboxes (name, smtp_host, smtp_port, smtp_encryption, smtp_username, smtp_password_encrypted, sender_email, sender_name, header_html, footer_html, is_default, is_active)
VALUES (:name, :smtp_host, :smtp_port, :smtp_encryption, :smtp_username, :smtp_password_encrypted, :sender_email, :sender_name, :header_html, :footer_html, :is_default, :is_active)'
);
}