Mandrill email attachments file path

前端 未结 2 1539
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 23:11

I am trying to add some attachments to an email that is being sent using the mandrill api via a php wrapper. I have tried a number of different things to try to successfully att

相关标签:
2条回答
  • 2021-02-01 23:26

    OK. So thanks to Kaitlin for her input. The PHP way to deal with this is to get the file and then base64_encode it:

    $attachment = file_get_contents(WWW_ROOT.'files/downloads/file.pdf');
    $attachment_encoded = base64_encode($attachment); 
    

    and then in the attachments part of the mandrill array you pass the :

    "attachments" => array(
            array(
                'content' => $attachment_encoded,
                'type' => "application/pdf",
                'name' => 'file.pdf',
            )
    

    So easy! Thanks again Kaitlin!

    0 讨论(0)
  • 2021-02-01 23:37

    It looks like you're passing a parameter called path, but the Mandrill API doesn't take the path of a file for attachments. If you're using the send or send-template call, attachments should be an associative array (hash) with three keys: type, name, and content.

    The content parameter should be the contents of the file as a Base64 encoded string, so instead of path, you'll want to get the file contents, Base64 encode them, and then pass them in a parameter called content instead of path.

    You can see the full details of the parameters, including for attachments, in the Mandrill API docs here: https://mandrillapp.com/api/docs/messages.html#method=send

    0 讨论(0)
提交回复
热议问题