我正在尝试下载并保存POST中存在的附件文件,因为Mailgun路由URL POST会在收到电子邮件后立即启动。
这是我的代码:
这是我可以从POST获得的POST列表。
$content_type = $_POST['Content-Type'];
$date = $_POST['Date'];
$from = $_POST['From'];
$in_reply_to = $_POST['In-Reply-To'];
$message_id = $_POST['Message-Id'];
$mime_version = $_POST['Mime-Version'];
$received = $_POST['Received'];
$references = $_POST['References'];
$subject = $_POST['Subject'];
$to = $_POST['To'];
$x_envelope_from = $_POST['X-Envelope-From'];
$x_mailgun_incoming = $_POST['X-Mailgun-Incoming'];
$x_received = $POST['X-Received'];
$body_html = $_POST['body-html'];
$body_plain = $_POST['body-plain'];
$domain = $_POST['domain'];
$from = $_POST['from'];
$message_headers = $_POST['message-headers'];
$message_url = $_POST['message-url'];
$recipient = $_POST['recipient'];
$sender = $_POST['sender'];
$signature = $_POST['signature'];
$stripped_html = $_POST['stripped-html'];
$stripped_signature = $_POST['stripped-signature'];
$stripped_text = $_POST['stripped-text'];
$subject = $_POST['subject'];
$timestamp = $_POST['timestamp'];
$token = $_POST['token'];
$event = $_POST['event'];
$attachment_count = $_POST['attachment-count'];
在这里,我可以从$ _FILES访问附件数组
$attachment = $_FILES;
$pathToDownloadDirectory = "/downloads/";
// var_dump($_FILES);
// echo"<br><br>POST Dumping Begins-->";
// var_dump($_POST);
在这里,我正在下载特定Mailgun Route POST url的所有附件,并将它们存储在名为“ downloads”的本地文件夹中。
以下代码摘自StackOverFlow帖子。我之所以重新发布,是因为互联网上仍然没有任何文章可以正确解释如何读取Mailgun POST响应并按照用户定义的方式对其进行处理。
无需任何操作即可获取文件。如何获得它们?
foreach($attachment as $file)
{
if(!(move_uploaded_file($file['tmp_name'], $pathToDownloadDirectory . $file['name'])))
{
echo"Nil";
}else
{
echo "NCL";
}
}