Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
<?php
// contact.php - Contact Form Handler for Widows Health Foundation
// Email configuration
$to_email = "KWilliams@widowshealthfoundation.org"; // Change this to your email
$from_email = "noreply@widowshealthfoundation.org"; // Change this to match your domain
// Initialize variables
$success = false;
$error = false;
$message = "";
// Check if form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Sanitize and validate input
$name = filter_var(trim($_POST["name"]), FILTER_SANITIZE_STRING);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$phone = filter_var(trim($_POST["phone"]), FILTER_SANITIZE_STRING);
$subject = filter_var(trim($_POST["subject"]), FILTER_SANITIZE_STRING);
$user_message = filter_var(trim($_POST["message"]), FILTER_SANITIZE_STRING);
// Validate required fields
if (empty($name) || empty($email) || empty($subject) || empty($user_message)) {
$error = true;
$message = "Please fill in all required fields.";
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = true;
$message = "Please enter a valid email address.";
} else {
// Prepare email content
$email_subject = "WHF Contact Form: " . $subject;
$email_body = "You have received a new message from the Widows Health Foundation website contact form.\n\n";
$email_body .= "Name: $name\n";
$email_body .= "Email: $email\n";
$email_body .= "Phone: $phone\n";
$email_body .= "Subject: $subject\n\n";
$email_body .= "Message:\n$user_message\n";
// Email headers
$headers = "From: $from_email\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
// Send email
if (mail($to_email, $email_subject, $email_body, $headers)) {
$success = true;
$message = "Thank you for contacting us! Your message has been sent successfully. We will respond as soon as possible.";
} else {
$error = true;
$message = "Sorry, there was an error sending your message. Please try again or contact us directly at 252-706-1664.";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form - Widows Health Foundation</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f4f4f4;
padding: 2rem;
}
.container {
max-width: 800px;
margin: 0 auto;
background-color: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #667eea;
margin-bottom: 1rem;
}
.success-message {
background-color: #d4edda;
color: #155724;
padding: 1rem;
border-radius: 4px;
margin-bottom: 1rem;
border: 1px solid #c3e6cb;
}
.error-message {
background-color: #f8d7da;
color: #721c24;
padding: 1rem;
border-radius: 4px;
margin-bottom: 1rem;
border: 1px solid #f5c6cb;
}
.btn {
display: inline-block;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 12px 30px;
text-decoration: none;
border-radius: 5px;
font-weight: 600;
transition: transform 0.3s, box-shadow 0.3s;
margin-top: 1rem;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}
</style>
</head>
<body>
<div class="container">
<h1>Contact Form Submission</h1>
<?php if ($success): ?>
<div class="success-message">
<?php echo $message; ?>
</div>
<?php elseif ($error): ?>
<div class="error-message">
<?php echo $message; ?>
</div>
<?php endif; ?>
<a href="index.html" class="btn">Return to Home Page</a>
</div>
</body>
</html>
a few seconds ago