Reputation: 9230
I have the following JSON from a Mailgun webhook (Delivered) that I need to extract the subject line from.
They do not appear to be following a typical key value JSON format, short of a bunch of foreach loops is there a way to extract this data?
[["Received", "by luna.mailgun.net with SMTP mgrt 8734663311733; Fri, 03 May 2013 18:26:27 +0000"], ["Content-Type", ["multipart/alternative", {"boundary": "eb663d73ae0a4d6c9153cc0aec8b7520"}]], ["Mime-Version", "1.0"], ["Subject", "Test deliver webhook"], ["From", "Bob <[email protected]>"], ["To", "Alice <[email protected]>"], ["Message-Id", "<[email protected]>"], ["X-Mailgun-Variables", "{\"my_var_1\": \"Mailgun Variable #1\", \"my-var-2\": \"awesome\"}"], ["Date", "Fri, 03 May 2013 18:26:27 +0000"], ["Sender", "[email protected]"]]
Upvotes: 3
Views: 784
Reputation: 173642
The reason why it's not a dictionary is because in emails you can have the same header appear more than once.
You just a single loop, though:
$subject = null;
foreach ($data as $header) {
if ($header[0] == 'Subject') {
$subject = $header[1];
break;
}
}
Upvotes: 3