Spaces:
Running
Running
Download contact.php from docker1/cpanel-site-hosting: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/spaces/docker1/cpanel-site-hosting/resolve/main/contact.php
- Command line
-
hf download hf://spaces/docker1/cpanel-site-hosting/contact.php
-
curl -L -o contact.php https://huggingface.co/spaces/docker1/cpanel-site-hosting/resolve/main/contact.php
1.93 kB
| // cPanel compatible contact form processor | |
| // Place this in the same directory as your index.html | |
| // Configure your email here | |
| $to = "your-email@example.com"; // <-- CHANGE THIS TO YOUR EMAIL | |
| $subject = "New Contact Form Submission"; | |
| // Check if form was submitted | |
| if ($_SERVER["REQUEST_METHOD"] == "POST") { | |
| // Collect and sanitize form data | |
| $name = filter_var(trim($_POST["name"]), FILTER_SANITIZE_STRING); | |
| $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL); | |
| $message = filter_var(trim($_POST["message"]), FILTER_SANITIZE_STRING); | |
| // Validation | |
| $errors = []; | |
| if (empty($name)) { | |
| $errors[] = "Name is required"; | |
| } | |
| if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
| $errors[] = "Valid email is required"; | |
| } | |
| if (empty($message)) { | |
| $errors[] = "Message is required"; | |
| } | |
| // If no errors, send email | |
| if (empty($errors)) { | |
| $email_subject = "New Message from $name"; | |
| $email_body = "Name: $name\n"; | |
| $email_body .= "Email: $email\n\n"; | |
| $email_body .= "Message:\n$message\n"; | |
| $headers = "From: $email\r\n"; | |
| $headers .= "Reply-To: $email\r\n"; | |
| $headers .= "X-Mailer: PHP/" . phpversion(); | |
| // Attempt to send email | |
| if (mail($to, $email_subject, $email_body, $headers)) { | |
| // Success - redirect back with success message | |
| header("Location: index.html?status=success#contact"); | |
| exit(); | |
| } else { | |
| // Failed to send | |
| header("Location: index.html?status=error#contact"); | |
| exit(); | |
| } | |
| } else { | |
| // Validation errors | |
| header("Location: index.html?status=validation#contact"); | |
| exit(); | |
| } | |
| } else { | |
| // Not a POST request | |
| header("Location: index.html"); | |
| exit(); | |
| } | |