diff --git a/public/api/contact.php b/public/api/contact.php new file mode 100644 index 0000000..d6d7093 --- /dev/null +++ b/public/api/contact.php @@ -0,0 +1,64 @@ + 'Method not allowed']); + exit; +} + +$data = json_decode(file_get_contents('php://input'), true); +if (!$data) { + http_response_code(400); + echo json_encode(['error' => 'Invalid JSON']); + exit; +} + +$name = htmlspecialchars(trim($data['name'] ?? ''), ENT_QUOTES); +$phone = htmlspecialchars(trim($data['phone'] ?? ''), ENT_QUOTES); +$email = htmlspecialchars(trim($data['email'] ?? ''), ENT_QUOTES); +$message = htmlspecialchars(trim($data['message'] ?? ''), ENT_QUOTES); + +if (!$name || !$message) { + http_response_code(400); + echo json_encode(['error' => 'Missing required fields']); + exit; +} + +$BOT_TOKEN = '8138813013:AAElH2L5NspRLSdiFjDz6Qf32n4G24P_cj8'; +$CHAT_ID = '-5230603582'; + +$text = "🔔 Заявка с sag24.ru\n\n"; +$text .= "👤 Имя: {$name}\n"; +if ($phone) $text .= "📱 Телефон: {$phone}\n"; +if ($email) $text .= "📧 Email: {$email}\n"; +$text .= "\n💬 Сообщение:\n{$message}\n"; +$text .= "\n⏰ " . date('d.m.Y H:i', time() + 3 * 3600) . " MSK"; + +$payload = json_encode([ + 'chat_id' => $CHAT_ID, + 'text' => $text, + 'parse_mode' => 'HTML', +]); + +$ch = curl_init("https://api.telegram.org/bot{$BOT_TOKEN}/sendMessage"); +curl_setopt_array($ch, [ + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $payload, + CURLOPT_HTTPHEADER => ['Content-Type: application/json'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 10, +]); +$result = curl_exec($ch); +$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); +curl_close($ch); + +if ($httpCode === 200) { + echo json_encode(['success' => true]); +} else { + http_response_code(500); + echo json_encode(['error' => 'Failed to send notification']); +} diff --git a/src/config.js b/src/config.js index 7a59350..a66a37f 100644 --- a/src/config.js +++ b/src/config.js @@ -1,5 +1,5 @@ // Настройки для связи и формы export const WHATSAPP_PHONE = '74953637476' // без + export const TELEGRAM_USERNAME = 'sag24ru' // @username без @ -export const FORM_ENDPOINT = '' // https://formspree.io/f/XXXXXXX — оставить пустым, будет mailto: +export const FORM_ENDPOINT = '/api/contact.php' export const EMAIL = 'info@sag24.ru'