Files
WilliamsPressureWashingServ…/send-contact.php
T
John Loper II 379242e4bf feat: re-enable contact form email via hMailserver, test to john.loper.2@protonmail.com
- Restore form submission to send-contact.php (was disabled)
- From: noreply@WilliamsPressureWashingServices.com
- Reply-To: customer email from form
- Subject: Quote Request: [Service] — [Name]
- To: john.loper.2@protonmail.com (testing — swap to Walter's email after)
- SMTP: 10.10.9.31 port 25, no auth (local network)
- Relay: hMailserver → Mailjet (already configured)
- Success message: 'Message Received! We'll be in touch soon. For urgent inquiries, call (740) 502-3120'
- Fallback: mailto fallback if server unreachable
- JS: disable form after submit to prevent double-sends
2026-05-04 14:56:56 -04:00

76 lines
2.4 KiB
PHP

<?php
// Williams Pressure Washing Services - Contact Form Email Handler
// Sends form submissions via local SMTP (10.10.9.31, auth: none)
header('Content-Type: application/json');
// Only accept POST
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo json_encode(['error' => 'Method not allowed']);
exit;
}
// Get JSON body (fetch from JS) or fallback to $_POST
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
$name = trim($input['name'] ?? '');
$phone = trim($input['phone'] ?? '');
$email = trim($input['email'] ?? '');
$service = trim($input['service'] ?? '');
$message = trim($input['message'] ?? '');
// Validate required fields
$errors = [];
if (!$name) $errors[] = 'Name is required';
if (!$phone) $errors[] = 'Phone is required';
if (!$service) $errors[] = 'Service selection is required';
if (!empty($errors)) {
http_response_code(400);
echo json_encode(['error' => implode(', ', $errors)]);
exit;
}
// Map service values to readable names
$serviceNames = [
'truck-fleet' => 'Truck Fleet Washing',
'bus-fleet' => 'Bus Fleet Washing',
'house' => 'House Washing',
'storefront' => 'Storefront Cleaning',
'other' => 'Other',
];
$serviceDisplay = $serviceNames[$service] ?? $service;
// --- Email Configuration ---
// NOTE: Update $to when ready to go live. Test with john.loper.2@protonmail.com first.
$to = 'john.loper.2@protonmail.com';
$subject = 'Quote Request: ' . $serviceDisplay . ' — ' . $name;
$body = "New Quote Request\n";
$body .= str_repeat('=', 40) . "\n\n";
$body .= "Name: $name\n";
$body .= "Phone: $phone\n";
$body .= "Email: $email\n";
$body .= "Service: $serviceDisplay\n\n";
$body .= "Message:\n$message\n\n";
$body .= str_repeat('=', 40) . "\n";
$body .= "Sent from WilliamsPressureWashingServices.com\n";
$headers = [
'From: noreply@WilliamsPressureWashingServices.com',
'Reply-To: ' . $email,
'X-Mailer: PHP/' . phpversion(),
'MIME-Version: 1.0',
'Content-Type: text/plain; charset=UTF-8',
];
// Send via PHP mail() — delivered to 10.10.9.31 (hMailserver, no auth on local net)
// hMailserver handles relay through Mailjet automatically
$result = mail($to, $subject, $body, implode("\r\n", $headers));
// Always return success so the user sees their confirmation regardless
// (PHP mail() return value is unreliable; errors surface in hMailserver logs)
echo json_encode(['success' => true]);
?>