57 lines
2.0 KiB
PHP
57 lines
2.0 KiB
PHP
<?php /* Name: process_contact.php
|
|
Beschreibung: Verarbeitung von Kontaktformular-Anfragen
|
|
- Speichert in admin_messages
|
|
- Sendet Mail an technik@nak-reinickendorf.de */
|
|
|
|
if (session_status() == PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
|
|
$pdo = require_once($_SERVER['DOCUMENT_ROOT']."/intranet_repo/general_files/ini/database.php");
|
|
require_once $_SERVER['DOCUMENT_ROOT'].'/intranet_repo/general_files/ini/send_mail.php';
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
|
|
http_response_code(405);
|
|
echo json_encode(['success' => false, 'error' => 'Methode nicht erlaubt']);
|
|
exit;
|
|
}
|
|
|
|
// Felder auslesen
|
|
$name = trim($_POST["contact_name"] ?? '');
|
|
$email = trim($_POST["contact_email"] ?? '');
|
|
$subject = trim($_POST["contact_subject"] ?? 'Kontaktanfrage');
|
|
$message = trim($_POST["contact_message"] ?? '');
|
|
|
|
// Validierung
|
|
if (empty($name) || empty($email) || empty($message)) {
|
|
http_response_code(400);
|
|
echo json_encode(['success' => false, 'error' => 'Bitte alle Felder ausfüllen.']);
|
|
exit;
|
|
}
|
|
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
http_response_code(400);
|
|
echo json_encode(['success' => false, 'error' => 'Ungültige E-Mail-Adresse.']);
|
|
exit;
|
|
}
|
|
|
|
// In admin_messages speichern
|
|
$stmt = $pdo->prepare("INSERT INTO admin_messages (type, sender_name, sender_email, subject, message) VALUES ('contact', ?, ?, ?, ?)");
|
|
$stmt->execute([$name, $email, $subject, $message]);
|
|
|
|
// Mail an Admin-Team (Admin + Technik)
|
|
$mail_betreff = "Kontaktanfrage: {$subject}";
|
|
$mail_nachricht = "Neue Kontaktanfrage über das Intranet:\n\n";
|
|
$mail_nachricht .= "Name: {$name}\n";
|
|
$mail_nachricht .= "E-Mail: {$email}\n";
|
|
$mail_nachricht .= "Betreff: {$subject}\n\n";
|
|
$mail_nachricht .= "Nachricht:\n{$message}";
|
|
|
|
send_admin_team_mail($pdo, $mail_betreff, $mail_nachricht);
|
|
|
|
// JSON-Antwort für AJAX
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['success' => true, 'message' => 'Nachricht wurde gesendet.']);
|
|
exit;
|
|
?>
|