Files
Schnappix-Web/tester_backend.php

44 lines
1.2 KiB
PHP

<?php
error_reporting(0);
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, true);
if (!$input || empty($input['email'])) {
http_response_code(400);
echo json_encode(['error' => 'Ungültige Eingabe']);
exit;
}
$email = filter_var($input['email'], FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
http_response_code(400);
echo json_encode(['error' => 'Ungültige E-Mail Adresse']);
exit;
}
// Send notification to Ntfy
$ntfyUrl = 'https://ntfy.orfel.de/Schnappix-App-Testing';
$message = "E-Mail: $email";
$ch = curl_init($ntfyUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Title: Neue Tester-Anmeldung',
'Tags: calling,bust_in_silhouette'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_exec($ch);
curl_close($ch);
echo json_encode(['success' => true]);
exit;
}
http_response_code(405);
echo json_encode(['error' => 'Method not allowed']);