How can I send file attachments via Mailgun by using URLs from a jQuery uploader? For instance:
$emailOutcome = $mgService->deliverEmail($clientDomain, [
'fromAddress' => 'Active Member <[email protected]>',
'toAddress' => '[email protected]',
'subjectLine' => 'Test Email',
'messageBody' => 'This is a test message.'
], [
'attachments' => ['@/alternative/path/document.txt']
]);
hey, mailgun expects a file resource, not a url. you can grab the file with something like file_get_contents and then pass that to the deliverEmail func. hope this helps!
The solution that worked for me was to fetch the file contents from the URL programmatically in order to create a file resource dynamically. I used PHP’s cURL functions to download the file data and stored it in a temporary file. This temporary resource was then uploaded directly via Mailgun. This approach allows you to work with URL-based files without having to permanently store them on the server. It streamlines the process and addresses Mailgun’s requirement for direct file resources.
In my experience, handling file attachments through URL uploads to Mailgun required an extra step to download the data first. I accomplished it by using PHP’s stream_context_create to perform a simple file_get_contents fetch and writing the contents to a temporary file. Then I passed that file to Mailgun’s API. While this approach works, be mindful of error handling during the download process and potential issues with file size limits. Adjusting the timeout and validating the file type help maintain reliability when processing user uploads.
hey u, ive been workin on this too. i used temp device streams + file_get_contents to generate a file resource. works ok if u ensure proper mime type support, kinda messy but does the trick!