title: JSON Post in PHP (CSP-Report)
body: <p>Today, I implemented the <a href="https://developer.mozilla.org/en-US/docs/Security/CSP" rel="nofollow" title="Content-Security-Policy &#40;CSP&#41;">Content-Security-Policy (CSP)</a>. I also included the <code>report-uri</code> so it sends a <strong>POST</strong> request to <code>myserver.com/csp-report.php</code>. As MDN explains in their website, the <strong>POST</strong> request is like this:</p>
  
  <pre><code>{
    "csp-report": {
      "document-uri": "http://example.com/signup.html",
      "referrer": "http://evil.example.net/haxor.html",
      "blocked-uri": "http://evil.example.net/injected.png",
      "violated-directive": "img-src *.example.com",
      "original-policy": "default-src 'self'; img-src 'self' *.example.com; report-uri /_/csp-reports",
    }
  }
  </code></pre>
  
  <p>I want to email this info, to reports@myserver.com. Currently, I have this code but it just emails "Array() Array()"</p>
  
  <pre><code>&lt;?php
  $tars = Array("reports@myserver.com", "webm@myserver.com");
  $from = "notify@myserver.com";
  $subject = "CSP Report";
  $text = print_r($_POST, true);
  $text = (isSet($_GET["text"]) ? $_GET["text"] : $text);
  foreach($tars as $tar){
      $e = mail($tar,$subject,$text,"From: $from");
  }
  if($e){
      header("Content-type: text/javascript"); 
      echo 'console.log("Email Sent");';
      exit();
  }
  ?&gt;
  </code></pre>