[Vuejs]-Sending file from html form with Laravel-Mailgun API

0👍

This is how I’ve finally done it. Problem was coming from the backend, I had to add file_get_contents to get all the file data contained into one string.

    $mgClient->messages()->send($domain,
        array('from'    => env('MAIL_FROM_ADDRESS'),
            'to'      => $request->emailAddress,
            'cc' => env('MAIL_CC'),
            'subject' => 'Greetings from Eatology',
            'template'    => 'welcome-template',
            'attachment' => [
                [
                    'fileContent' => file_get_contents($request->file('file')),
                    'filename' => 'attachment.' . $request->file('file')->extension()
                ]
            ],
            'h:X-Mailgun-Variables'    => $mailgunVariables)
    );

Leave a comment