Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

learn@karmanya.co.in's avatar

Attaching remote files which are stored in AWS s3 bucket, while sending an Email in Laravel.

Hi,

I want to attach a file which is located in my AWS s3 bucket while sending an email. But i don't want to download it into my local for attaching. I can not find any documentation regarding this in laravel, could you please help me on this.

0 likes
8 replies
jekinney's avatar

The General accepted way is provide a download link. File attachments can get tricky with email clients and users email settings. Which case your system may end up sending more emails and pissed off users.

More so if it's a large file. Hard enough to format and add images for a pretty email :).

denjaland's avatar

No one else has a better answer? I have a customer also requiring documents to be sent as attachment which is stored in AWS bucket. We are sending download links now, but customer wants it attached nevertheless.

I'm running in quite some troubles when we want to use Mailables with an attachment hosted on S3.

->addAttachment won't work as it only works with local paths. -> AddAttachmentData won't work as it crashes on json encoding when the Mailable is being queued...

Cronix's avatar

Download from S3, store locally, build the email with the local attachment, send email, delete copied resource.

1 like
himbol's avatar

I found that the Mailable attachData method actually works quite nicely.

This is the solution I used:

$file = Storage::disk('s3')->get($file->file_location); $mail->attachData($file, 'file_name.pdf');

1 like
lindstrom's avatar

I was looking for the solution to this problem tonight and came across this thread. So let's give it a proper answer in case anyone other than me goes searching before checking the docs. As of at least 5.7, you can use attachFromStorageDisk

From the docs for 5.8:

The attachFromStorageDisk method may be used if you need to specify a storage disk other than your default disk:

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
   return $this->view('email.orders.shipped')
               ->attachFromStorageDisk('s3', '/path/to/file');
}

There is an optional third parameter for name. If not specified, it uses basename on the path. An optional fourth parameter takes an array of options.

6 likes
ben_01's avatar
    public function build() {
        return $this->markdown('markdown file')->attach('/path/to/file');
    }
Kawesome's avatar

Tested with laravel 12, initially tried Attachment::fromStorageDisk('s3', $user->cv)->as('name.pdf')->withMime('application/pdf') but Attachment::fromUrl() worked for me. Note i am working with URLs saved in my database

Please or to participate in this conversation.