Implement email functionality and improve booking system

Features:
- Add real email sending with PHP mail() function
- Create HTML email templates for bookings
- Send booking notifications to bands
- Send confirmation emails to customers
- Add email field to bands table and profile
- Enable guest bookings without login
- Improve form validation and UX
- Add migration script for database updates

This fixes the non-working email system and improves the reservation/booking process significantly.
This commit is contained in:
Claude
2025-12-02 21:01:02 +00:00
parent 798a2785e7
commit acc50dbb5d
6 changed files with 420 additions and 12 deletions
+163
View File
@@ -0,0 +1,163 @@
# Email & Buchungssystem Updates
## Änderungen vom 2. Dezember 2025
### ✅ Implementierte Features:
#### 1. **Echte Email-Funktionalität** (`includes/email.php`)
- ✨ PHP `mail()` Funktion implementiert statt nur Logging
- ✅ HTML-Email-Support mit professionellen Templates
- 📧 Automatische Headers (From, Reply-To, Content-Type)
- 📝 Logging bleibt erhalten für Debugging
#### 2. **Email-Template-System**
- 🎨 Professionelle HTML-Email-Templates mit Styling
- 🎸 "booking_request" - Email an die Band
- ✅ "booking_confirmation" - Bestätigung an den Kunden
- 🎨 Gelbes Branding (#f4b807) passend zur Plattform
#### 3. **Verbesserte Buchungsanfragen** (`anfrage.php`)
- 📧 Automatische Email an Band bei neuer Anfrage
- ✅ Bestätigungs-Email an Kunden
- 👥 **Gäste-Buchungen** ohne Login möglich
- ✔️ Bessere Formular-Validierung
- 📅 Datum-Mindestauswahl (nur zukünftige Daten)
#### 4. **Band-Email-Verwaltung** (`profil.php`)
- 📧 Bands können eigene Email-Adresse hinterlegen
- 📝 Klare Beschriftung: "Email für Buchungsanfragen"
- 💾 Email wird in der Datenbank gespeichert
#### 5. **Datenbank-Updates** (`database.sql`)
- 🗄️ Neue Spalte `email` in `bands` Tabelle
- 📜 Migration-Script: `migrate_add_band_email.php`
---
## 📋 Installations-Anleitung
### Schritt 1: Migration ausführen
```bash
php migrate_add_band_email.php
```
### Schritt 2: Mail-Server konfigurieren
Stelle sicher, dass PHP's `mail()` Funktion auf dem Server konfiguriert ist:
- Ubuntu/Debian: `sudo apt-get install sendmail`
- Oder verwende einen SMTP-Relay wie Postfix
### Schritt 3: Testen
1. Als Band einloggen
2. Profil bearbeiten und Email-Adresse hinzufügen
3. Als Gast oder Kunde eine Buchungsanfrage senden
4. Prüfe die Emails (und `storage/logs/mail.log`)
---
## 🎯 Neue Funktionen im Detail
### Email an Band (booking_request)
```
Enthält:
- Event-Datum, Ort, Typ
- Budget
- Nachricht des Kunden
- Kontaktdaten (Name, Email)
- Professionelles Layout
```
### Email an Kunde (booking_confirmation)
```
Enthält:
- Bestätigung der Anfrage
- Event-Details
- Hinweis auf Rückmeldung der Band
- Support-Kontakt
```
### Gäste-Buchungen
```
- Keine Registrierung nötig
- Name + Email Pflichtfelder
- Email-Validierung
- Gleiche Funktionalität wie eingeloggte User
```
---
## 🔧 Konfiguration
### Email-Absender
In `includes/config.php`:
```php
const SITE_NAME = 'GetYourBand';
const SUPPORT_EMAIL = 'support@getyourband.ch';
```
### Band-Email Fallback
Falls Band keine Email hinterlegt hat:
```php
info@[bandname].ch
```
(Leerzeichen werden entfernt, lowercase)
---
## 📝 Nächste Schritte (Optional)
### Empfohlene Erweiterungen:
1. **PHPMailer Integration** für SMTP-Support
2. **Email-Queue** für große Mengen
3. **Email-Templates per Datenbank** konfigurierbar
4. **Email-Benachrichtigungen** für:
- Status-Änderungen von Anfragen
- Neue Bewertungen
- Profil-Freigaben
### SMTP mit PHPMailer (Beispiel):
```bash
composer require phpmailer/phpmailer
```
Dann in `includes/email.php` ersetzen:
```php
use PHPMailer\PHPMailer\PHPMailer;
// ... SMTP Konfiguration
```
---
## 🐛 Debugging
### Email kommt nicht an?
1. Prüfe `storage/logs/mail.log` - werden Emails geloggt?
2. Prüfe Server Mail-Logs: `tail -f /var/log/mail.log`
3. Teste PHP mail(): `php -r "mail('test@example.com', 'Test', 'Test');"`
4. Prüfe Spam-Ordner
### Häufige Probleme:
- **sendmail nicht installiert**: `sudo apt-get install sendmail`
- **Port 25 blockiert**: Verwende SMTP-Relay
- **SPF/DKIM fehlt**: Emails landen im Spam
---
## ✨ Zusammenfassung
**Vorher:**
- ❌ Emails wurden nur geloggt
- ❌ Keine echten Email-Benachrichtigungen
- ❌ Gäste konnten nicht buchen
- ❌ Bands hatten keine Email-Verwaltung
**Nachher:**
- ✅ Echte Email-Versand mit HTML-Templates
- ✅ Automatische Benachrichtigungen an Band & Kunde
- ✅ Gäste-Buchungen möglich
- ✅ Bands verwalten ihre Email-Adresse
- ✅ Professionelles Design
- ✅ Bessere Validierung
---
**Viel Erfolg! 🎸🎵**
+42 -9
View File
@@ -26,12 +26,31 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'message' => trim((string) $_POST['message'] ?? ''),
];
$guestName = trim($_POST['guest_name'] ?? '');
$guestEmail = trim($_POST['guest_email'] ?? '');
if (!$data['event_date'] || !$data['location']) {
$error = 'Bitte Datum und Ort ausfüllen.';
} elseif (!$user && (!$guestName || !$guestEmail)) {
$error = 'Bitte geben Sie Ihren Namen und Email-Adresse an.';
} elseif (!$user && !filter_var($guestEmail, FILTER_VALIDATE_EMAIL)) {
$error = 'Bitte geben Sie eine gültige Email-Adresse an.';
} else {
createRequest($data);
$message = 'Anfrage gespeichert und an die Band gemeldet.';
sendEmail('info@' . preg_replace('/\s+/', '', strtolower($band['name'])) . '.ch', 'Neue Anfrage', 'Neue Anfrage für ' . $band['name']);
$customer = $user;
if (!$user && $guestName && $guestEmail) {
$customer = ['name' => $guestName, 'email' => $guestEmail];
}
sendBookingRequestEmail($band, $data, $customer);
$confirmEmail = $user['email'] ?? $guestEmail ?? null;
if ($confirmEmail) {
sendBookingConfirmationEmail($confirmEmail, $band, $data);
}
$message = 'Anfrage erfolgreich gesendet! Die Band wurde benachrichtigt und wird sich bei Ihnen melden.';
}
}
@@ -55,20 +74,34 @@ $settings = settings();
<?php if ($message): ?><div class="alert alert-success"><?= htmlspecialchars($message) ?></div><?php endif; ?>
<?php if ($error): ?><div class="alert alert-error"><?= htmlspecialchars($error) ?></div><?php endif; ?>
<form method="post">
<label>Event-Datum
<input type="date" class="form-control" name="event_date" required>
<?php if (!$user): ?>
<div style="background: #fff3cd; padding: 15px; margin-bottom: 20px; border-radius: 4px;">
<strong>Gast-Buchung</strong>
<p style="margin: 5px 0 0 0; font-size: 14px;">Sie sind nicht eingeloggt. Bitte geben Sie Ihre Kontaktdaten an.</p>
</div>
<label>Ihr Name *
<input type="text" class="form-control" name="guest_name" required>
</label>
<label>Ort / Location
<label>Ihre Email *
<input type="email" class="form-control" name="guest_email" required>
</label>
<hr style="margin: 20px 0;">
<?php endif; ?>
<label>Event-Datum *
<input type="date" class="form-control" name="event_date" min="<?= date('Y-m-d') ?>" required>
</label>
<label>Ort / Location *
<input type="text" class="form-control" name="location" placeholder="Zürich, Kaufleuten" required>
</label>
<label>Event-Typ
<input type="text" class="form-control" name="event_type" placeholder="Hochzeit, Firmenfeier">
<input type="text" class="form-control" name="event_type" placeholder="Hochzeit, Firmenfeier, Geburtstag">
</label>
<label>Budget (CHF)
<input type="number" class="form-control" name="budget" placeholder="4500">
<input type="number" class="form-control" name="budget" placeholder="4500" min="0">
</label>
<label>Nachricht
<textarea class="form-control" name="message" rows="4"></textarea>
<label>Nachricht / Besondere Wünsche
<textarea class="form-control" name="message" rows="4" placeholder="Erzählen Sie uns mehr über Ihr Event..."></textarea>
</label>
<button class="btn-primary">Anfrage senden</button>
</form>
+1
View File
@@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS bands (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
name TEXT NOT NULL,
email TEXT,
city TEXT,
genre TEXT,
price INTEGER DEFAULT 0,
+172 -1
View File
@@ -1,10 +1,181 @@
<?php
function sendEmail(string $to, string $subject, string $message): void
require_once __DIR__ . '/config.php';
function sendEmail(string $to, string $subject, string $message, bool $isHtml = true): bool
{
$logDir = __DIR__ . '/../storage/logs';
if (!is_dir($logDir)) {
mkdir($logDir, 0775, true);
}
$entry = sprintf("%s\nTo: %s\nSubject: %s\n%s\n---\n", date('c'), $to, $subject, $message);
file_put_contents($logDir . '/mail.log', $entry, FILE_APPEND);
$headers = [
'From: ' . SITE_NAME . ' <' . SUPPORT_EMAIL . '>',
'Reply-To: ' . SUPPORT_EMAIL,
'X-Mailer: PHP/' . phpversion(),
'MIME-Version: 1.0'
];
if ($isHtml) {
$headers[] = 'Content-Type: text/html; charset=UTF-8';
} else {
$headers[] = 'Content-Type: text/plain; charset=UTF-8';
}
return mail($to, $subject, $message, implode("\r\n", $headers));
}
function sendBookingRequestEmail(array $band, array $requestData, ?array $customer = null): bool
{
$bandEmail = $band['email'] ?? 'info@' . preg_replace('/\s+/', '', strtolower($band['name'])) . '.ch';
$subject = 'Neue Buchungsanfrage für ' . $band['name'];
$message = emailTemplate('booking_request', [
'band_name' => $band['name'],
'event_date' => date('d.m.Y', strtotime($requestData['event_date'])),
'location' => $requestData['location'],
'event_type' => $requestData['event_type'] ?: 'Nicht angegeben',
'budget' => $requestData['budget'] ? formatPrice($requestData['budget']) : 'Nicht angegeben',
'message' => $requestData['message'] ?: 'Keine Nachricht',
'customer_name' => $customer['name'] ?? 'Gast',
'customer_email' => $customer['email'] ?? 'Keine Email angegeben',
]);
return sendEmail($bandEmail, $subject, $message);
}
function sendBookingConfirmationEmail(string $customerEmail, array $band, array $requestData): bool
{
$subject = 'Ihre Anfrage an ' . $band['name'] . ' wurde gesendet';
$message = emailTemplate('booking_confirmation', [
'band_name' => $band['name'],
'event_date' => date('d.m.Y', strtotime($requestData['event_date'])),
'location' => $requestData['location'],
'site_name' => SITE_NAME,
]);
return sendEmail($customerEmail, $subject, $message);
}
function emailTemplate(string $templateName, array $data): string
{
$templates = [
'booking_request' => '
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #f4b807; padding: 20px; text-align: center; }
.content { background: #fff; padding: 20px; border: 1px solid #ddd; }
.info-row { margin: 10px 0; padding: 10px; background: #f9f9f9; }
.label { font-weight: bold; color: #666; }
.footer { text-align: center; padding: 20px; color: #666; font-size: 12px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1 style="margin:0; color: #fff;">🎸 Neue Buchungsanfrage</h1>
</div>
<div class="content">
<p>Hallo <strong>' . htmlspecialchars($data['band_name']) . '</strong>,</p>
<p>Sie haben eine neue Buchungsanfrage erhalten:</p>
<div class="info-row">
<span class="label">Event-Datum:</span> ' . htmlspecialchars($data['event_date']) . '
</div>
<div class="info-row">
<span class="label">Ort:</span> ' . htmlspecialchars($data['location']) . '
</div>
<div class="info-row">
<span class="label">Event-Typ:</span> ' . htmlspecialchars($data['event_type']) . '
</div>
<div class="info-row">
<span class="label">Budget:</span> ' . htmlspecialchars($data['budget']) . '
</div>
<div class="info-row">
<span class="label">Nachricht:</span><br>' . nl2br(htmlspecialchars($data['message'])) . '
</div>
<h3>Kontaktdaten:</h3>
<div class="info-row">
<span class="label">Name:</span> ' . htmlspecialchars($data['customer_name']) . '
</div>
<div class="info-row">
<span class="label">Email:</span> <a href="mailto:' . htmlspecialchars($data['customer_email']) . '">' . htmlspecialchars($data['customer_email']) . '</a>
</div>
<p style="margin-top: 20px;">
Bitte kontaktieren Sie den Kunden direkt, um die Details zu besprechen.
</p>
</div>
<div class="footer">
Gesendet von ' . SITE_NAME . ' - Ihre Band-Vermittlungsplattform
</div>
</div>
</body>
</html>
',
'booking_confirmation' => '
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #f4b807; padding: 20px; text-align: center; }
.content { background: #fff; padding: 20px; border: 1px solid #ddd; }
.info-row { margin: 10px 0; padding: 10px; background: #f9f9f9; }
.label { font-weight: bold; color: #666; }
.footer { text-align: center; padding: 20px; color: #666; font-size: 12px; }
.success { background: #d4edda; border: 1px solid #c3e6cb; padding: 15px; margin: 15px 0; border-radius: 4px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1 style="margin:0; color: #fff;">✅ Anfrage gesendet</h1>
</div>
<div class="content">
<div class="success">
<strong>Ihre Anfrage wurde erfolgreich gesendet!</strong>
</div>
<p>Vielen Dank für Ihre Anfrage an <strong>' . htmlspecialchars($data['band_name']) . '</strong>.</p>
<h3>Details Ihrer Anfrage:</h3>
<div class="info-row">
<span class="label">Event-Datum:</span> ' . htmlspecialchars($data['event_date']) . '
</div>
<div class="info-row">
<span class="label">Ort:</span> ' . htmlspecialchars($data['location']) . '
</div>
<p style="margin-top: 20px;">
Die Band wird sich in Kürze bei Ihnen melden. Bitte überprüfen Sie auch Ihren Spam-Ordner.
</p>
<p>
Bei Fragen können Sie uns jederzeit unter <a href="mailto:' . SUPPORT_EMAIL . '">' . SUPPORT_EMAIL . '</a> erreichen.
</p>
</div>
<div class="footer">
Vielen Dank, dass Sie ' . htmlspecialchars($data['site_name']) . ' nutzen!
</div>
</div>
</body>
</html>
',
];
return $templates[$templateName] ?? '';
}
+35
View File
@@ -0,0 +1,35 @@
<?php
/**
* Migration: Add email column to bands table
* Run this once to update existing databases
*/
require_once __DIR__ . '/includes/database.php';
try {
$pdo = db();
$columns = $pdo->query("PRAGMA table_info(bands)")->fetchAll(PDO::FETCH_ASSOC);
$hasEmail = false;
foreach ($columns as $column) {
if ($column['name'] === 'email') {
$hasEmail = true;
break;
}
}
if (!$hasEmail) {
echo "Adding email column to bands table...\n";
$pdo->exec("ALTER TABLE bands ADD COLUMN email TEXT");
echo "✓ Email column added successfully!\n";
} else {
echo "✓ Email column already exists.\n";
}
echo "\nMigration completed successfully!\n";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage() . "\n";
exit(1);
}
+7 -2
View File
@@ -13,9 +13,10 @@ if ($user['role'] === 'band') {
$band = $stmt->fetch(PDO::FETCH_ASSOC);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stmt = db()->prepare('UPDATE bands SET name = :name, city = :city, genre = :genre, price = :price, description = :description, style_tags = :tags WHERE id = :id');
$stmt = db()->prepare('UPDATE bands SET name = :name, email = :email, city = :city, genre = :genre, price = :price, description = :description, style_tags = :tags WHERE id = :id');
$stmt->execute([
':name' => $_POST['name'],
':email' => $_POST['email'] ?? null,
':city' => $_POST['city'],
':genre' => $_POST['genre'],
':price' => (int) $_POST['price'],
@@ -47,7 +48,11 @@ if ($user['role'] === 'band') {
<h2>Bandprofil</h2>
<form method="post">
<label>Bandname
<input class="form-control" name="name" value="<?= htmlspecialchars($band['name']) ?>">
<input class="form-control" name="name" value="<?= htmlspecialchars($band['name']) ?>" required>
</label>
<label>Email für Buchungsanfragen
<input class="form-control" type="email" name="email" value="<?= htmlspecialchars($band['email'] ?? '') ?>" placeholder="band@example.ch">
<small>An diese Adresse werden Buchungsanfragen gesendet</small>
</label>
<label>Ort
<input class="form-control" name="city" value="<?= htmlspecialchars($band['city']) ?>">