Enhance API functionality and security: Added rate limiting and domain validation across multiple API endpoints, improved error handling for missing or invalid parameters, and refactored email handling in contact form for better security and maintainability. Updated README.md with production build instructions and prerequisites.
This commit is contained in:
@@ -1,72 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* HexaHost.de E-Mail Test
|
||||
* Testet die E-Mail-Funktionalität ohne PHPMailer
|
||||
* HexaHost.de E-Mail Test (nur CLI oder lokale Entwicklung)
|
||||
*/
|
||||
|
||||
// Konfiguration laden
|
||||
require_once 'config.php';
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
$remoteAddr = $_SERVER['REMOTE_ADDR'] ?? '';
|
||||
$isLocal = in_array($remoteAddr, ['127.0.0.1', '::1'], true)
|
||||
|| filter_var($remoteAddr, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false;
|
||||
|
||||
if (!$isLocal) {
|
||||
http_response_code(403);
|
||||
exit('Forbidden');
|
||||
}
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../backend/config/mail-config.php';
|
||||
|
||||
// Test-E-Mail senden
|
||||
function testEmail() {
|
||||
$config = getHexaHostConfig();
|
||||
|
||||
// Test-Daten
|
||||
$test_data = [
|
||||
'firstName' => 'Test',
|
||||
'lastName' => 'Benutzer',
|
||||
'email' => 'test@example.com',
|
||||
'phone' => '+49 123 456789',
|
||||
'company' => 'Test GmbH',
|
||||
'subject' => 'test-email',
|
||||
'message' => 'Dies ist eine Test-E-Mail vom HexaHost.de Kontaktformular.'
|
||||
];
|
||||
|
||||
// E-Mail-Inhalt erstellen
|
||||
|
||||
$subject = '[HexaHost.de] Test-E-Mail';
|
||||
$message = "Test-E-Mail von HexaHost.de\n\n";
|
||||
$message .= "Name: " . $test_data['firstName'] . " " . $test_data['lastName'] . "\n";
|
||||
$message .= "E-Mail: " . $test_data['email'] . "\n";
|
||||
$message .= "Telefon: " . $test_data['phone'] . "\n";
|
||||
$message .= "Unternehmen: " . $test_data['company'] . "\n";
|
||||
$message .= "Nachricht: " . $test_data['message'] . "\n\n";
|
||||
$message .= "Zeitstempel: " . date('d.m.Y H:i:s') . "\n";
|
||||
$message .= "IP-Adresse: " . $_SERVER['REMOTE_ADDR'] . "\n";
|
||||
|
||||
// Headers
|
||||
|
||||
$headers = [
|
||||
'From: ' . $config['from_name'] . ' <' . $config['from_email'] . '>',
|
||||
'Reply-To: ' . $test_data['firstName'] . ' ' . $test_data['lastName'] . ' <' . $test_data['email'] . '>',
|
||||
'MIME-Version: 1.0',
|
||||
'Content-Type: text/plain; charset=UTF-8',
|
||||
'X-Mailer: HexaHost Test Email'
|
||||
'X-Mailer: HexaHost Test Email',
|
||||
];
|
||||
|
||||
// E-Mail senden
|
||||
$result = mail($config['to_email'], $subject, $message, implode("\r\n", $headers));
|
||||
|
||||
return $result;
|
||||
|
||||
return mail($config['to_email'], $subject, $message, implode("\r\n", $headers));
|
||||
}
|
||||
|
||||
// Test ausführen
|
||||
if (isset($_GET['test'])) {
|
||||
$result = testEmail();
|
||||
|
||||
if ($result) {
|
||||
echo "✅ Test-E-Mail wurde erfolgreich gesendet!";
|
||||
} else {
|
||||
echo "❌ Fehler beim Senden der Test-E-Mail.";
|
||||
}
|
||||
} else {
|
||||
echo "<h1>HexaHost.de E-Mail Test</h1>";
|
||||
echo "<p>Klicken Sie auf den Link, um eine Test-E-Mail zu senden:</p>";
|
||||
echo "<a href='?test=1'>Test-E-Mail senden</a>";
|
||||
|
||||
// Konfiguration anzeigen
|
||||
echo "<h2>Aktuelle Konfiguration:</h2>";
|
||||
$config = getHexaHostConfig();
|
||||
echo "<pre>";
|
||||
print_r($config);
|
||||
echo "</pre>";
|
||||
if (PHP_SAPI === 'cli') {
|
||||
echo testEmail() ? "Test-E-Mail gesendet.\n" : "Fehler beim Senden.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_GET['test'])) {
|
||||
echo testEmail()
|
||||
? 'Test-E-Mail wurde gesendet.'
|
||||
: 'Fehler beim Senden der Test-E-Mail.';
|
||||
} else {
|
||||
echo '<h1>HexaHost.de E-Mail Test</h1>';
|
||||
echo '<p><a href="?test=1">Test-E-Mail senden</a></p>';
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user