<?php
if(isset($_POST['name'])){

    $name = trim($_POST['name']);
    $phone = trim($_POST['phone']);
    $email = trim($_POST['email']);
    $subject = trim($_POST['subject']);
    $message = trim($_POST['message']);

    if($name=='' || $email=='' || $subject==''){
        echo '<div style="color:red;">All required fields must be filled.</div>';
    }
    elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
        echo '<div style="color:red;">Please enter a valid email address.</div>';
    }
    else{

        $to = "rahul@manaorganics.co.in"; // change email
        $mail_subject = $subject;
        $mail_message = 
        "Name: $name\n".
        "Phone: $phone\n".
        "Email: $email\n\n".
        "Subject: $subject\n\n".
        "Message:\n$message\n";

        $headers = "From: Website <no-reply@manaorganics.co.in>\r\n";
        $headers .= "Reply-To: $email\r\n";

        if(mail($to,$mail_subject,$mail_message,$headers)){
            echo '<div style="color:green;">✅ Your message has been sent successfully.</div>';
        }else{
            echo '<div style="color:red;">❌ Mail server error. Please try again later.</div>';
        }
    }
}
?>