如何使用json和php仅在正文中发送数据?

    <?php
$emparray = array();
if($_SERVER['REQUEST_METHOD'] == "POST")
{
    $name   = urldecode($_POST['name']);    
    $email = filter_var($_POST["email"],FILTER_SANITIZE_EMAIL); 
    $subject  = urldecode($_POST['subject']);
    $message   = urldecode($_POST['message']);
    $message_final = 'Name :-'.$name."
".'Email Id :-'.$email."
".'Message :-'.$message;      
    $to = 'xyz';
    if($name!=NULL && $email!=NULL && $subject!=NULL && $message!=NULL)
    {           
        if (!filter_var($email, FILTER_VALIDATE_EMAIL))
        {                   
            $emparray =array(
            'status' => 0, 'message' => 'Invalid Email Format');        
        }            
        else
        {
        $emparray= mail($to,$subject,$message_final);               
            $emparray =array(
            'status' => 1, 'message' => 'Thank you for writing us,Email sent successfully');                            
        }
    }
    else
    {
        $emparray =array(
        'status' => 0, 'message' => 'All fields are required');         
    }   
}
else
    {
        $emparray = array("status" => 0, "message" => "Request Method Not accepted");
    }

    echo json_encode($emparray,JSON_PRETTY_PRINT,JSON_FORCE_OBJECT);    
?>

I am using postman tool for testing. If I send data using headers with key value it goes like body. How to stop this to send data with headers too. I want if data will send from body then only it should work. If i send it from headers it should prompt me error of cant send data using headers.

Someone tells me about headers_sent function to overcome this issue. But im unable to implement it. please help me this the same.

You have to select body/raw/JSON (application/json).

Hope it works for you.

enter image description here