Hey,
what do I need todo to send html emails? - I am using the email templating engine from kirby.
I have created a html template
HTML Template
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Terminanfrage bestätigt</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #f9f9f9;
border-radius: 5px;
}
h2 {
color: #4a6fdc;
margin-top: 0;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
.content {
background-color: #fff;
padding: 20px;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
p {
margin-bottom: 10px;
}
ul {
margin: 15px 0;
padding-left: 20px;
}
li {
margin-bottom: 5px;
}
.signature {
margin-top: 30px;
padding-top: 15px;
border-top: 1px solid #eee;
}
@media only screen and (max-width: 620px) {
.container {
width: 100% !important;
}
}
</style>
</head>
<body>
<div class="container">
<h2>Vielen Dank für Ihre Anfrage</h2>
<div class="content">
<p>Sehr geehrte(r) <?= $vorname ?> <?= $nachname ?>,</p>
<p><?= $confirmationText ?></p>
<p>Ihre angefragten Termine:</p>
<ul>
<li>Tage: <?= $wochentageText ?></li>
<li>Zeiten: <?= $uhrzeitenText ?></li>
</ul>
<div class="signature">
<p>Mit freundlichen Grüßen</p>
<p>Ihr Team der <?= $siteName ?></p>
</div>
</div>
<p style="font-size: 12px; color: #999; margin-top: 20px; text-align: center;">
Dies ist eine automatisch generierte E-Mail, bitte antworten Sie nicht auf diese Nachricht.
</p>
</div>
</body>
</html>
and my plugin controller is in my view the same like in the cookbook recipe:
Snippet from ContactController.php
/**
* Send confirmation email to the customer
*/
protected function sendConfirmationEmail() {
// Check if sending confirmation is enabled
$sendConfirmation = $this->getConfig('general', 'copy_to_inquirer', true);
if (!$sendConfirmation) {
return;
}
$kirby = kirby();
// Collect form data for templates
$data = $this->collectFormData();
// Get config options
$sender = $this->getConfig('general', 'sender');
$subject = $this->getConfig('general', 'confirmation_subject');
// Send confirmation email using Kirby's built-in template system
try {
$kirby->email([
'from' => $sender,
'to' => $data['email'],
'subject' => $subject,
'template' => 'confirmation',
'data' => $data
]);
} catch (\Exception $e) {
// Just log but don't throw - confirm email failure shouldn't prevent success response
error_log('Fehler beim Senden der Bestätigungs-E-Mail: ' . $e->getMessage());
}
}
EDIT: I save all templates inside the plugin folder - this is the extension:
Plugin extension in index.php
'templates' => [
'emails/confirmation' => __DIR__ . '/templates/emails/confirmation.html.php',
'emails/request' => __DIR__ . '/templates/emails/request.html.php'
],
For testing I have no text version of the template (as introduced in issue 1557). I also have no extension like in this post. But all emails are received with Content-Type: text/plain; charset=UTF-8.
Already checked posts - maybe I’m blind ^^:
- Email-engine produces content-type: text/plain in HTML-Emails
- Sending an email with html-body contentSending an email with html-body content
- Email template with HTML: template not found
Thanks for the help ![]()