0 Best Reply Awards

  • Member Since 1 Month Ago
  • 20 Lessons Completed
  • 2 Favorites

8th January, 2018

DavidWeller01 left a reply on Accessing Mailgun Webhook Post Array • 1 week ago

{ "tags": [], "delivery-status": { "mx-host": "hotmail-com.olc.protection.outlook.com", "attempt-no": 1, "description": "", "session-seconds": 3.1470839977264404, "code": 250, "message": "OK" }, "storage": { "url": "https://se.api.mailgun.net/v3/domains/mg..co.uk/messages/eyJwIjpmYWxzZSwiayI6ImRmNDVhYTE4LTg2MTctNGE0NC1iMzE0LTY5MTEwY2RmNjUzYiIsInMiOiJhN2VjOGRjYjVhIiwiYyI6InRhbmtiIn0=", "key": "eyJwIjpmYWxzZSwiayI6ImRmNDVhYTE4LTg2MTctNGE0NC1iMzE0LTY5MTEwY2RmNjUzYiIsInMiOiJhN2VjOGRjYjVhIiwiYyI6InRhbmtiIn0=" }, "log-level": "info", "id": "Uwgwsef5SnG1JtgC9fH3kg", "campaigns": [], "user-variables": {}, "flags": { "is-routed": false, "is-authenticated": true, "is-system-test": false, "is-test-mode": false }, "recipient-domain": "hotmail.com", "timestamp": 1515418975.594767, "envelope": { "transport": "smtp", "sender": "[email protected]", "sending-ip": "", "targets": "[email protected]" }, "message": { "headers": { "to": "Mrs Katie Barnes [email protected]", "message-id": "5c5e0ed1e84fc6e02d31c49b0ace8397@www.hetasfitter.co.uk", "from": "[email protected]", "subject": "Ramsbottom Stoves Have Published Your Quotation, ref:1082" }, "attachments": [], "size": 5341 }, "recipient": "[email protected]", "event": "delivered" }

Above is the full posted array that is sent to me from the MailGun email service

I have done, json_decode($request->get('message-headers')); and looped through it with foreach() but it still returns the same as above.

I do an if statement to try and find the subject field in the loop but i cannot get this item and it's value. I want to use the subject field to find the same item in the database so i can update it's delivery status.

If you have an example of how you might go about looping through a nested array like the one above i can give it a try. I've looked all over the internet but not found anything that works.

Hope you can help me out here...not much hair left now :(

DavidWeller01 left a reply on Accessing Mailgun Webhook Post Array • 2 weeks ago

Ah right OK.

This is posted back from the mailgun services to a page of my choosing through a webhook service.

So what i am trying to work out is how do i filter through the JSON data so i can access each item such as message-id and subject.

In laravel i am doing it like this

public function delivered(Request $request) { // Dump to test //echo $request->get('recipient'); //echo $request->get('subject'); $headers = $request->get('message-headers');

    foreach ($headers as $header => $value){

    echo '<pre>';

        if ($header == 'subject'){
            echo 'subject: '.$value;

    echo '</pre>';

Any ideas Bobby?

Cheers, Dave

7th January, 2018

DavidWeller01 started a new conversation Accessing Mailgun Webhook Post Array • 2 weeks ago

What is the best way to filter through this data below. I am trying to access the subject in the header array but with no luck at all. I need to access the headers to cross ref in the database and update it's status. By the way this is only part of the post from Mailgun, i can access everything else except the message-headers

"message": { "headers": { "to": "Mr David Weller [email protected]", "message-id": "8326ffca98d45f37c85fe17c096f3359@www.hetasfitter.co.uk", "from": "Ramsbottom Stoves [email protected]", "subject": "Ramsbottom Stoves Survey Confirmation" }, "attachments": [], "size": 2510 },

Any help would be most welcome from a newbie...cheers!

Edit Your Profile

Want to change your profile photo? We pull from gravatar.com.