Update020920252221
This commit is contained in:
parent
6c64da0884
commit
6828c3f835
7 changed files with 130 additions and 77 deletions
|
|
@ -1,19 +1,25 @@
|
|||
<?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';
|
||||
|
||||
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';
|
||||
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');
|
||||
ini_set('error_log', '/home/amperion/private/php_errors.log');
|
||||
|
||||
// SMTP-Konfiguration laden
|
||||
$smtp_config = include '/home/amperion-test/private/smtp_config.php';
|
||||
$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;
|
||||
}
|
||||
|
||||
// Formulardaten abrufen
|
||||
$name = $_POST["name"] ?? '';
|
||||
|
|
@ -42,19 +48,20 @@ curl_setopt($ch, CURLOPT_POSTFIELDS, [
|
|||
'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));
|
||||
echo "<p>Server-Fehler. Bitte später erneut versuchen.</p>";
|
||||
exit;
|
||||
}
|
||||
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->SMTPDebug = 0; // Debug-Ausgabe deaktiviert
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $smtp_config['smtp_host'];
|
||||
$mail->Port = $smtp_config['smtp_port'];
|
||||
|
|
@ -62,17 +69,18 @@ if (!empty($response_data['success']) && $response_data['success'] === true) {
|
|||
$mail->Username = $smtp_config['smtp_username'];
|
||||
$mail->Password = $smtp_config['smtp_password'];
|
||||
$mail->SMTPSecure = $smtp_config['smtp_encryption'];
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->Encoding = 'base64';
|
||||
|
||||
// Absenderadresse prüfen
|
||||
if (empty($smtp_config['smtp_from'])) {
|
||||
throw new Exception("Absenderadresse nicht konfiguriert.");
|
||||
}
|
||||
$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
|
||||
|
|
@ -85,13 +93,14 @@ if (!empty($response_data['success']) && $response_data['success'] === true) {
|
|||
";
|
||||
|
||||
$mail->send();
|
||||
header("Location: /danke/"); // Leitet zu /danke/index.html um
|
||||
header("Location: /danke/");
|
||||
exit();
|
||||
} catch (Exception $e) {
|
||||
error_log("E-Mail-Fehler: " . $mail->ErrorInfo);
|
||||
error_log("E-Mail-Fehler: " . $e->getMessage());
|
||||
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