AMPERION_Webpage/static/send.php

107 lines
3.9 KiB
PHP
Raw Normal View History

2025-09-01 16:48:21 +02:00
<?php
// PHPMailer laden
2025-09-02 22:21:50 +02:00
require '/home/amperion/htdocs/www.amperion.at/vendor/phpmailer/src/PHPMailer.php';
require '/home/amperion/htdocs/www.amperion.at/vendor/phpmailer/src/SMTP.php';
require '/home/amperion/htdocs/www.amperion.at/vendor/phpmailer/src/Exception.php';
2025-09-01 16:48:21 +02:00
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Fehler-Logging
ini_set('display_errors', 0);
ini_set('log_errors', 1);
2025-09-02 22:21:50 +02:00
ini_set('error_log', '/home/amperion/private/php_errors.log');
2025-09-01 16:48:21 +02:00
// SMTP-Konfiguration laden
2025-09-02 22:21:50 +02:00
$smtp_config = include '/home/amperion/private/smtp_config.php';
// Prüfe, ob die Absenderadresse gültig ist
if (empty($smtp_config['smtp_from']) || !filter_var($smtp_config['smtp_from'], FILTER_VALIDATE_EMAIL)) {
error_log("Ungültige Absenderadresse in smtp_config.php: " . print_r($smtp_config, true));
echo "<p>Server-Konfigurationsfehler. Bitte später erneut versuchen.</p>";
exit;
}
2025-09-01 16:48:21 +02:00
// Formulardaten abrufen
$name = $_POST["name"] ?? '';
$email = $_POST["email"] ?? '';
$company = $_POST["company"] ?? '';
$phone = $_POST["phone"] ?? '';
$subject = $_POST["subject"] ?? '';
$message = $_POST["message"] ?? '';
$legal_consented = isset($_POST["legal_consented"]) ? "Ja" : "Nein";
$hcaptcha_response = $_POST["h-captcha-response"] ?? '';
// hCaptcha-Secret aus Environment laden
$hcaptcha_secret = getenv('HCAPTCHA_SECRET');
if (!$hcaptcha_secret) {
error_log("hCaptcha Secret nicht gesetzt!");
echo "<p>Server-Konfigurationsfehler. Bitte später erneut versuchen.</p>";
exit;
}
// hCaptcha-Überprüfung mit cURL
$ch = curl_init('https://hcaptcha.com/siteverify');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'secret' => $hcaptcha_secret,
'response' => $hcaptcha_response,
'remoteip' => $_SERVER['REMOTE_ADDR'] ?? null,
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
error_log("cURL-Fehler bei hCaptcha: " . curl_error($ch));
2025-09-02 22:21:50 +02:00
echo "<p>Server-Fehler. Bitte später erneut versuchen.</p>";
exit;
2025-09-01 16:48:21 +02:00
}
curl_close($ch);
$response_data = json_decode($response, true);
// E-Mail mit PHPMailer senden, wenn Captcha ok
if (!empty($response_data['success']) && $response_data['success'] === true) {
$mail = new PHPMailer(true);
try {
2025-09-02 22:21:50 +02:00
$mail->SMTPDebug = 0; // Debug-Ausgabe deaktiviert
2025-09-01 16:48:21 +02:00
$mail->isSMTP();
$mail->Host = $smtp_config['smtp_host'];
$mail->Port = $smtp_config['smtp_port'];
$mail->SMTPAuth = true;
$mail->Username = $smtp_config['smtp_username'];
$mail->Password = $smtp_config['smtp_password'];
$mail->SMTPSecure = $smtp_config['smtp_encryption'];
2025-09-02 22:21:50 +02:00
$mail->CharSet = 'UTF-8';
$mail->Encoding = 'base64';
2025-09-01 16:48:21 +02:00
2025-09-02 22:21:50 +02:00
// Absenderadresse prüfen
if (empty($smtp_config['smtp_from'])) {
throw new Exception("Absenderadresse nicht konfiguriert.");
}
2025-09-01 16:48:21 +02:00
$mail->setFrom($smtp_config['smtp_from'], $smtp_config['smtp_from_name']);
$mail->addAddress('office@amperion.at'); // Empfänger
if (!empty($email)) {
$mail->addReplyTo($email, $name);
}
$mail->Subject = mb_encode_mimeheader("Neue Kontaktanfrage: $subject", 'UTF-8');
$mail->Body = "
Name: $name
E-Mail: $email
Unternehmen: $company
Telefon: $phone
Betreff: $subject
Nachricht: $message
Datenschutz zugestimmt: $legal_consented
";
$mail->send();
2025-09-02 22:21:50 +02:00
header("Location: /danke/");
2025-09-01 16:48:21 +02:00
exit();
} catch (Exception $e) {
2025-09-02 22:21:50 +02:00
error_log("E-Mail-Fehler: " . $e->getMessage());
2025-09-01 16:48:21 +02:00
echo "<p>Es gab ein Problem beim Senden der Nachricht. Bitte versuche es später erneut.</p>";
}
} else {
error_log("hCaptcha-Überprüfung fehlgeschlagen: " . print_r($response_data, true));
echo "<p>Bitte bestätige, dass du kein Roboter bist.</p>";
}
2025-09-02 22:21:50 +02:00
?>