This is probably pretty simple but I am banging my head against a wall.
I am attempting to parse the data that Mailgun sends via a webhook to my application.
So I set-up a simple script to just test things:-
<?php
if(!empty($_POST))
{
$file = fopen('mail'.time().'.txt','w');
ob_start();
var_dump($_POST);
fwrite($file, ob_get_clean());
fclose($file);
}
?>
Yeah - its ugly I know.
I receive the response and it is written to file no problem.
The issue is that the attachments part of the response is not picked up this way.
The following Django code illustrates what you are meant to do - but I am obviously being either thick or a noob as i can't fathom how to get the PHP equivalent of
def on_incoming_message(request):
if request.method == 'POST':
sender = request.POST.get('sender')
recipient = request.POST.get('recipient')
subject = request.POST.get('subject', '')
body_plain = request.POST.get('body-plain', '')
body_without_quotes = request.POST.get('stripped-text', '')
for key in request.FILES:
file = request.FILES[key]# note: other MIME headers are also posted here...
# attachments:
# do something with the file
return HttpResponse('OK')
The bit I am being a bit dumb about is
for key in request.FILES:
file = request.FILES[key]# note: other MIME headers are also posted here...
How do I access the parts 'outside' of the POST
request.
For clarity:-
- Email recieved by mailgun and forwarded to myserver.com/mailgun (WORKS)
- Parsing the result - can get everything up to 'TOKEN' in list of items Mailgun sends
- Postbin DOES show the attachments - so what on earth do I put to get the attachments - what is the equivalent PHP for the Django code above.
Thanks for the help - I am crying at how simple this is and the fact I am stuck but a fresh pair of eyes is desperately needed!