bpb-website/sendEmail.php
2025-01-13 21:27:50 -05:00

36 lines
1.1 KiB
PHP

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate and sanitize inputs
$name = htmlspecialchars(trim($_POST['name']));
$email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL);
$message = htmlspecialchars(trim($_POST['message']));
// Check if the email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Invalid email address.";
exit;
}
// Prepare email
$to = "info@beachpartyballons.com"; // Replace with your business email
$headers = "From: $name <$email>\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$email_body = "You have received a new message from your website contact form.\n\n";
$email_body .= "Name: $name\n";
$email_body .= "Email: $email\n";
$email_body .= "Phone: $phone\n";
$email_body .= "Message:\n$message\n";
// Send email
if (mail($to, $subject, $email_body, $headers)) {
echo "Message sent successfully!";
} else {
echo "Failed to send message. Please try again later.";
}
} else {
echo "Invalid request.";
}
?>