title: Sending json to php server using jquery ajax - json error
body: <p>I have problem with my form on my webpage. I am trying to use ajax and json to send the form values to php server, but I can't make properly json object. </p>
  
  <p><strong>My JS code</strong>   </p>
  
  <pre><code>function sendJsonOpenPopout () {
      $('.submitBtn').click(function(e){
          e.preventDefault();
  
          var subject = $('.subject').val();
          var email = $('.email').val();
          var message = $('.message').val();
  
          var dataObject = {
              subject: subject,
              email: email,
              message: message
          }
  
          $.ajax({
          type: 'POST',
          url: '../../kontakt.php',
          contentType: "application/json",
          dataType: 'json',
          data: dataObject,
  
          success: function(data){
               alert('Items added');
          },
  
          error: function(){
              console.log('You have fail');
          }
  
          //success: function(){
              //var createdDiv = '&lt;div class="divToBeCentered"&gt;&lt;p class="dataText"&gt;Wiadomość została wysłana pomyślnie.\brDziękuję za kontakt.&lt;/p&gt;&lt;/div&gt;';
               //$('body').append(createdDiv);
           //}
      });
  });
  </code></pre>
  
  <p><strong>My PHP code</strong></p>
  
  <pre><code>&lt;?php 
      $str_json = file_get_contents('php://input'); //($_POST doesn't work here)
      $response = json_decode($str_json, true); // decoding received JSON to array
      $subject = $response[0];
      $from = $response[1];
      $message = $response[2];
  
      $to = "lubycha@gmail.com"; 
      $subject = $_POST['subject'];
      $from = $_POST['email'];
      $message = $_POST['message'];
      $headers = "Content-Type: text/html; charset=UTF-8"; 
      mail($to,$subject,$message,$headers);
  ?&gt;
  </code></pre>
  
  <p>I know there is similar question already asked, but the answers didn't help me.</p>
  
  <p>Thanks for helping.</p>