title: How can I send a discord webhook using PHP?
body: <p>I'm trying to make a form send the information to a discord channel, but im having trouble making the webhook connection since it just keeps saying <code>{"message": "Cannot send an empty message", "code": 50006}</code>
  This is my code:</p>
  
  <pre><code>$url = "https://discordapp.com/api/webhooks/xxxxxxxxx";
  
  $hookObject = json_encode([
      "content" =&gt; "A message will go here",
      "username" =&gt; "MyUsername",
  ], JSON_FORCE_OBJECT);
  
  $ch = curl_init();
  var_dump($hookObject);
  curl_setopt_array( $ch, [
      CURLOPT_URL =&gt; $url,
      CURLOPT_POST =&gt; true,
      CURLOPT_POSTFIELDS =&gt; $hookObject,
      CURLOPT_HTTPHEADER =&gt; [
          "Length" =&gt; strlen( $hookObject ),
          "Content-Type" =&gt; "application/json"
      ]
  ]);
  
  $response = curl_exec( $ch );
  curl_close( $ch );
  </code></pre>