📂 FileMgr
📍
/home/kientructhaiha/htdocs/kientructhaiha.com/api
✏️ Edit File: /home/kientructhaiha/htdocs/kientructhaiha.com/api/contact.php
⬅ Kembali
<?php /** * API xử lý form liên hệ từ website * Endpoint: /api/contact.php */ require_once __DIR__ . '/backend/config.php'; if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Validate CSRF token hoặc just do basic validation header('Content-Type: application/json'); $full_name = isset($_POST['full_name']) ? sanitize($_POST['full_name']) : ''; $email = isset($_POST['email']) ? sanitize($_POST['email']) : ''; $phone = isset($_POST['phone']) ? sanitize($_POST['phone']) : ''; $subject = isset($_POST['subject']) ? sanitize($_POST['subject']) : 'Yêu cầu tư vấn'; $message = isset($_POST['message']) ? sanitize($_POST['message']) : ''; // Validation if (empty($full_name) || empty($email) || empty($phone) || empty($message)) { json_response(false, 'Vui lòng điền đầy đủ các trường bắt buộc'); } // Validate email if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { json_response(false, 'Email không hợp lệ'); } // Insert vào database $full_name_db = $mysqli->real_escape_string($full_name); $phone_db = $mysqli->real_escape_string($phone); $email_db = $mysqli->real_escape_string($email); $subject_db = $mysqli->real_escape_string($subject); $message_db = $mysqli->real_escape_string($message); $result = $mysqli->query("INSERT INTO consultations (full_name, phone, email, subject, message, status) VALUES ('$full_name_db', '$phone_db', '$email_db', '$subject_db', '$message_db', 'new')"); if ($result) { // TODO: Send email notification to admin json_response(true, 'Cảm ơn bạn! Chúng tôi sẽ liên hệ với bạn sớm nhất'); } else { json_response(false, 'Có lỗi xảy ra. Vui lòng thử lại sau'); } } else { json_response(false, 'Method not allowed'); } ?>
💾 Simpan File
Batal
⬅ Naik ke kientructhaiha.com
1 item
Nama
Tipe
Ukuran
Diubah
Aksi
🐘
contact.php
php
1.9 KB
2026-05-21 05:51
✏️ Edit
👁️ View
🗑 Hapus