Mailgun having trouble dealing with attachments PHP

梦想的初衷 提交于 2019-12-08 04:23:48

问题


I'm currently connecting to Mailgun's webhooks so I can get any emails sent through and pass it somewhere else.

I've managed to deal with the subject, from and body inputs of the API, but I'm currently having trouble grabbing any attachments to an email.

Mailgun says that they send through a multipart file, but I have tried to catch it and write out the info into a file, but it comes back as an empty array...

$file = fopen(__DIR__ . '/files.txt','w') or die("Can't open file.");
ob_start();
var_dump($_FILES);
fwrite($file, ob_get_clean()) or die("Can't save to file.");
fclose($file);

Within the Post information, I get an attachments parameter which has such things like a url, content-type, name etc. I have tried to go the the url of each attachment, but I get a login box asking for a username and password and says "Server says: MG API". I have no idea if I need to pass something here so I can retrieve the attachment as a file to pass it on.

If anyone could help me out here, then I would truly appreciate it.

Thank you.


回答1:


Great question,

As you said from the inbound webhook coming from mailgun to your server you're being sent a URL from which to fetch the attachment.

In my case it's https://api.mailgun.net/v2/domains/<<<MYDOMAIN>>>>/messages/WyJjZTL.....SJd/attachments/0

Now if I authenticate to that URL with my username(api) and password, I can fetch the attachement. example:

https://API:PASSWORD@api.mailgun.net/v2/domains/<<<MYDOMAIN>>>>/messages/WyJjZTL.....SJd/attachments/0

The password is simply the API key, that you can find in the control panel on the left. (https://mailgun.com/cp)

hope this works for you as well as its working for me, best regards



来源:https://stackoverflow.com/questions/26257216/mailgun-having-trouble-dealing-with-attachments-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!