title: How do I receive and use webhook data sent from Mailgun?
body: <p>I am using webhooks from the MailGun API to notify me when an email has been delivered.</p>
  
  <p>I used the RequestBin service to see the data that is being sent:</p>
  
  <pre><code>domain: domain.com
  token: 6o02nxnu-7grjkvkzxdyn2lsm0w7fagidgxzon8-cucz8u15w0
  signature: a4d27e390495691fb4b8fb76b3b8a71c90cf8cd467140f5c3d36e023ec343e5c
  Message-Id: &lt;20140721155006.120305.72293@domain.com&gt;
  timestamp: 1405957808
  X-Mailgun-Sid: WyJjZjMyNCIsICJjaHJpc3NlY2tsZXJAZ21haWwuY29tIiwgIjAxNzBiNSJd
  message-headers: [["Received", "by luna.mailgun.net with HTTP; Mon, 21 Jul 2014 15:50:06 +0000"], ["Content-Type", ["multipart/alternative", {"boundary": "21586684bc984a0cbc485d4a862fc34c"}]], ["Mime-Version", "1.0"], ["Subject", "Please Check Your Account"], ["From", "Sender Name &lt;testemail@domain.com&gt;"], ["To", "Chris &lt;anotheremail@gmail.com&gt;"], ["X-Mailgun-Sid", "WyJjZjMyNCIsICJjaHJpc3NlY2tsZXJAZ21haWwuY29tIiwgIjAxNzBiNSJd"], ["Date", "Mon, 21 Jul 2014 15:50:08 +0000"], ["Sender", "testemail@domain.com"]]
  recipient: email@domain.com
  event: delivered
  </code></pre>
  
  <p>I am now trying to use their information sent via a POST array and insert it into my DB.</p>
  
  <p>The following variables I can grab directly from the POST array that they are sending:</p>
  
  <pre><code>$recipient_email = $_POST['recipient']; //This works
  $timestamp = $_POST['timestamp']; //This works
  </code></pre>
  
  <p>The following variables I cannot get to directly from the POST array. They are within a datatype in the "message-headers" variable that I am not familiar with. How can I access those?</p>
  
  <pre><code>$sender_name = ?;
  $sender_email = ?;
  $recipient_name = ?;
  $subject = ?;
  
  $sql = 'INSERT into mail SET
          from_name = "'.$sender_name.'",
          from_email = "'.$sender_email.'",
          to_name = "'.$recipient_name.'",
          to_email = "'.$recipient_email.'",
          subject = "'.$subject.'",
          date = "'.$timestamp.'"';
  
  $result = $conn-&gt;query($sql) or die(mysqli_error($conn));
  </code></pre>