Mailgun Sent mail With attachment

I realise this is old but I’ve just run into this problem and this page is pretty much the only info I can find on the net. So I hope this will assist someone else. After talking to MailGun support I’ve found the following works with the current API.

Cycles through an array of zero to n attachment files:

    $attachmentsArray = array('file1.txt', 'file2.txt');
    $x = 1;
    foreach( $attachmentsArray as $att )
    {
        $msgArray["attachment[$x]"] = curl_file_create( $att );
        $x ++;
    }

    // relevant cURL parameter, $msgArray also contains to, from, subject  parameters etc.
    curl_setopt($ch, CURLOPT_POSTFIELDS,$msgArray);

Leave a Comment