Mandrill email attachments file path

前端 未结 2 1547
爱一瞬间的悲伤
爱一瞬间的悲伤 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!

提交回复
热议问题