How do I access an array nested inside a JSON element with PHP. Here is the code I'm using (simplified for the example), I can access from_email, html, subject
etc. easily, but how would I access the to
email address recipient@addresshere.co.uk
? Do I need some sort of foreach
loop, on the basis that there could be more than one entry?
JSON
{
"event": "inbound",
"msg": {
"dkim": {},
"email": "myemail@addresshere.co.uk",
"from_email": "example.sender@mandrillapp.com",
"headers": {},
"html": "This is an example inbound message.",
"raw_msg": "Received: from mail115.us4.mandrillapp.com",
"sender": null,
"spam_report": {},
"spf": {},
"subject": "This is an example webhook message",
"tags": [ ],
"template": null,
"text": "This is an example inbound message.",
"text_flowed": false,
"to": [
[
"recipient@addresshere.co.uk",
null
]
]
}
}
PHP
$emailp = urldecode($_REQUEST['mandrill_events']); // The above JSON
$email = array_pop(json_decode($emailp));
$from_email = $email->msg->from_email; // From email
$html = $email->msg->html; // HTML Message
$subject = $email->msg->subject; // Subject
$to = ????
Thanks