检索附件 Sendgrid 入站解析

Retrieving attachments Sendgrid inbound parse

我正在尝试使用 Sendgrid 入站解析,并且我的脚本可以正常工作。 webhook 被执行,我可以将消息保存到我们的应用程序数据库中。现在我有一个关于如何解析附件的问题。我已经研究了一段时间但没有运气。在入站请求中有一个附件信息,其中包含有关附件的信息,但它实际存储在哪里?或者如果可能的话,我如何检索并将其存储在我们的服务器上或在线查看?

谢谢

$html = $_POST['html'];
$recipient = $_POST['to'];
$subject = $_POST['subject'];
$envelope = json_decode($_POST['envelope']);
$sender = $envelope->from;
$user = -1;
$created_at = date('Y-m-d H:i:s');


$attachments = $_POST['attachments'];


if($attachments > 0)
{
    $attachment_info = json_decode($_POST['attachment-info'], true);
    
    for($i = 1; $i <= $attachments; $i++)
    {
        
        //process attachments how???
        $file = $attachment_info['attachment'.$i];
        // {"filename":"shutterstock_745545163.jpg","name":"shutterstock_745545163.jpg","type":"image/jpeg","content-id":"ii_ku4rffz40"}
        //what to I do whit this info? how do I retrieve the attachment from this emial?? 
        
        
    }
    
}

   
$params = [

    'type' => 'email',
    'customer_id' => get_customer($sender),
    'direction' => 'in',
    'sender' => $sender,
    'recipient' => $recipient,
    'subject' => $subject,
    'message' => $html,
    'status' => 'delivered',
    'user' => 0,
    
];

//process email
//this stores email into DB
process_email($params);

此处为 Twilio SendGrid 开发人员布道师。

所有文件都与 webhook 中的其余数据一起发送。该请求是一个 multipart/form-data 请求,因此文件也作为请求的一部分发送。

您将在 PHP 的 $_FILES 数组中找到文件的内容。有关详细信息,请参阅此 PHP documentation for how multipart requests are managed and this PHP example for handling the SendGrid inbound parse webhook