<?php
header('Content-Type: text/html; charset=UTF-8');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); exit('Method not allowed'); }
$to='REPLACE-WITH-YOUR-EMAIL@example.com';
function clean($v){return trim(str_replace(["\r","\n"],' ',(string)$v));}
$name=clean($_POST['name']??''); $email=clean($_POST['email']??''); $phone=clean($_POST['phone']??''); $project=clean($_POST['project']??''); $msg=trim((string)($_POST['message']??''));
if(!$name || !filter_var($email,FILTER_VALIDATE_EMAIL) || !$msg){http_response_code(400);exit('Please complete the required fields.');}
$body="Name: $name\nEmail: $email\nPhone: $phone\nProject: $project\n\n$msg";
$headers='From: website@rcmdrywallpaint.com' . "\r\n" . 'Reply-To: '.$email;
mail($to,'Website estimate request - '.$name,$body,$headers);
header('Location: thank-you.html');
?>