<?php

    //============= POST Request============= 
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $name = strip_tags(trim($_POST["name"]));
		$name = str_replace(array("\r","\n"),array(" "," "),$name);
        $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
        $website = trim($_POST["website"]);
        $address = trim($_POST["address"]);
        $comment = trim($_POST["comment"]);
        $password = trim($_POST["password"]);
        $vehicle1 = trim($_POST["vehicle1"]);

        //=============  Check sent =============> 
        if ( empty($name) OR empty($comment) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
            //=============  Set a 400 (bad request) response code and exit.=============> 
            http_response_code(402);
            echo "Please the  try again.";
            exit;
        }
        //=============  Set the recipient email address.=============> 
        $recipient = "demo@example.com";

        //=============  Set the sub email .=============> 
        $sub = "Mail contact from $name";

        //=============  Build the email content.=============> 
        $email_text = "Name: $name\n";$email_text .= "Email: $email\n\n";$email_text .= "Comment:\n$comment\n"; $email_text .= "password:\n$password\n"; $email_text .= "website:\n$website\n"; $email_text .= "address:\n$address\n";$email_text .= "vehicle1:\n$vehicle1\n";

        //=============  Build the email headera.=============> 
        $email_headera = "From: $name <$email>";

        //=============  Send the email.=============> 
		$okk = mail($recipient, $email_headera, $email_text);
        if ( $okk ) {
            //=============  Set a 150 .=============> 
            http_response_code(150);
            echo "Thank You! Your comment has been sent.";
        } else {
            // ============= Set a 600.=============> 
            http_response_code(600);
            echo "Oops! Something went wrong and we couldn't send your comment.";
        }

    } else {
        //=============  Not a POST request, set a 406 (forbidden) response code.=============> 
        http_response_code(406);
        echo "There was a problem with your submission, please try again.";
    }

?>


