Update010920251648
This commit is contained in:
parent
4055e3ae54
commit
29e3a85eae
6 changed files with 162 additions and 36 deletions
97
static/send.php
Normal file
97
static/send.php
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
// PHPMailer laden
|
||||
require '/home/amperion-test/htdocs/test.amperion.at/vendor/phpmailer/src/PHPMailer.php';
|
||||
require '/home/amperion-test/htdocs/test.amperion.at/vendor/phpmailer/src/SMTP.php';
|
||||
require '/home/amperion-test/htdocs/test.amperion.at/vendor/phpmailer/src/Exception.php';
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
// Fehler-Logging
|
||||
ini_set('display_errors', 0);
|
||||
ini_set('log_errors', 1);
|
||||
ini_set('error_log', '/home/amperion-test/private/php_errors.log');
|
||||
|
||||
// SMTP-Konfiguration laden
|
||||
$smtp_config = include '/home/amperion-test/private/smtp_config.php';
|
||||
|
||||
// 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));
|
||||
}
|
||||
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 {
|
||||
$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'];
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
// UTF-8 für Betreff und Inhalt erzwingen
|
||||
$mail->CharSet = 'UTF-8'; // <-- WICHTIG
|
||||
$mail->Encoding = 'base64'; // <-- WICHTIG
|
||||
|
||||
$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();
|
||||
header("Location: /danke/"); // Leitet zu /danke/index.html um
|
||||
exit();
|
||||
} catch (Exception $e) {
|
||||
error_log("E-Mail-Fehler: " . $mail->ErrorInfo);
|
||||
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>";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue