35 lines
1.0 KiB
PHP
Executable File
35 lines
1.0 KiB
PHP
Executable File
<?php
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
// Collect form data
|
|
$name = htmlspecialchars($_POST['name']);
|
|
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
|
|
$message = htmlspecialchars($_POST['message']);
|
|
|
|
// Validate email
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
echo "Invalid email format";
|
|
exit;
|
|
}
|
|
|
|
// Email details
|
|
$to = "veatio8@gmail.com";
|
|
$subject = "New Contact Form Submission";
|
|
$headers = "From: " . $email . "\r\n" .
|
|
"Reply-To: " . $email . "\r\n" .
|
|
"X-Mailer: PHP/" . phpversion();
|
|
|
|
$body = "Name: $name\n";
|
|
$body .= "Email: $email\n\n";
|
|
$body .= "Message:\n$message";
|
|
|
|
// Error handling with detailed information
|
|
if (mail($to, $subject, $body, $headers)) {
|
|
echo "Email sent successfully!";
|
|
} else {
|
|
// Use error_get_last() to capture the last error
|
|
$error = error_get_last()['message'];
|
|
echo "Failed to send email. Error: " . $error;
|
|
}
|
|
}
|
|
?>
|