Files
site-teste/processContact.php

93 lines
4.6 KiB
PHP

<?php
// Sanitize inputs
$name = isset($_POST['name']) ? trim(strip_tags($_POST['name'])) : '';
$email = isset($_POST['email']) ? trim(filter_var($_POST['email'], FILTER_SANITIZE_EMAIL)) : '';
$phone = isset($_POST['phone']) ? trim(strip_tags($_POST['phone'])) : 'Not provided';
$address_zip = isset($_POST['address_zip']) ? trim(strip_tags($_POST['address_zip'])) : '';
$phone_allowed = isset($_POST['phone_allowed']) ? trim(strip_tags($_POST['phone_allowed'])) : 'Yes';
$best_time = isset($_POST['best_time']) ? trim(strip_tags($_POST['best_time'])) : 'Anytime';
$subject = isset($_POST['subject']) ? trim(strip_tags($_POST['subject'])) : '';
$message = isset($_POST['message']) ? trim(strip_tags($_POST['message'])) : '';
$marketing_optin = isset($_POST['marketing_optin']) ? 'Yes' : 'No';
$errors = array();
// Form Validation
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "You must enter a valid email address.";
}
if (empty($name)) {
$errors[] = "You must enter your name.";
}
if (empty($address_zip)) {
$errors[] = "You must enter your Address or ZIP Code.";
}
if (empty($subject)) {
$errors[] = "You must enter a subject.";
}
if (empty($message) || strlen($message) < 10) {
$errors[] = "Message must be at least 10 characters long.";
}
if (!empty($errors)) {
$errortext = "";
foreach ($errors as $error) {
$errortext .= "<li>" . htmlspecialchars($error) . "</li>";
}
echo "<div class='thanks failure'>The following errors occurred:<ul>" . $errortext . "</ul></div>";
exit;
}
// 1. Email to Company Admin
$to = "contact@eddysconstruction.com";
$admin_body = "You have received a new contact request:\n\n";
$admin_body .= "Name: " . $name . "\n";
$admin_body .= "Email: " . $email . "\n";
$admin_body .= "Phone: " . $phone . "\n";
$admin_body .= "Address / ZIP Code: " . $address_zip . "\n";
$admin_body .= "Phone Call Allowed: " . $phone_allowed . "\n";
$admin_body .= "Best Time for Contact: " . $best_time . "\n";
$admin_body .= "Marketing Consent: " . $marketing_optin . "\n";
$admin_body .= "Subject: " . $subject . "\n\n";
$admin_body .= "Message:\n" . $message . "\n";
$admin_headers = array();
$admin_headers[] = "MIME-Version: 1.0";
$admin_headers[] = "Content-Type: text/plain; charset=UTF-8";
$admin_headers[] = "From: Eddy's Construction <contact@eddysconstruction.com>";
$admin_headers[] = "Reply-To: " . $name . " <" . $email . ">";
$admin_headers[] = "X-Mailer: PHP/" . phpversion();
$sent = @mail($to, "New Estimate Request: " . $subject, $admin_body, implode("\r\n", $admin_headers));
// 2. Auto-reply Email to Customer
if ($sent) {
$client_subject = "We received your request - Eddy's Construction & Masonry";
$client_body = "Hello " . htmlspecialchars($name) . ",\n\n";
$client_body .= "Thank you for reaching out to Eddy's Construction & Masonry LLC.\n\n";
$client_body .= "We have received your request for an estimate/information regarding: \"" . htmlspecialchars($subject) . "\". Our team is currently reviewing your message and will get back to you shortly.\n\n";
$client_body .= "IMPORTANT: To ensure our future communications reach your inbox, please reply directly to this email or add contact@eddysconstruction.com to your contacts list.\n\n";
$client_body .= "If you did not see this message in your primary inbox, please check your Spam or Junk Mail folder.\n\n";
$client_body .= "Best regards,\n";
$client_body .= "Eddy's Construction & Masonry Team\n";
$client_body .= "(508) 782-2159 | https://eddysconstruction.com\n\n";
$client_body .= "--- \n";
$client_body .= "If you ever wish to unsubscribe from our informational updates, please reply to this email with 'UNSUBSCRIBE' in the subject line or visit https://eddysconstruction.com/privacy.html.";
$client_headers = array();
$client_headers[] = "MIME-Version: 1.0";
$client_headers[] = "Content-Type: text/plain; charset=UTF-8";
$client_headers[] = "From: Eddy's Construction <contact@eddysconstruction.com>";
$client_headers[] = "Reply-To: contact@eddysconstruction.com";
@mail($email, $client_subject, $client_body, implode("\r\n", $client_headers));
// Indicativo para o JS redirecionar para a página thankyou.html
echo "REDIRECT:thankyou.html";
} else {
echo "<div class='thanks failure'>Server error: Unable to send email right now. Please call us directly at (508) 782-2159.</div>";
}