Skip to content

Out of memory when sending large disk attachments #51620

Closed
@bytestream

Description

@bytestream

Laravel Version

10.48.12

PHP Version

8.2.19

Database Driver & Version

No response

Description

Sending a mailable with a large disk attachment results in an out of memory exception. This is because the whole file is loaded into memory at

$storage->get($attachment['path']),

It should be sent to Symfony mailer as a stream, which is already supported

* @param string|resource $data

Steps To Reproduce

/**
 * Get the attachments for the message.
 *
 * @return array<int, \Illuminate\Mail\Mailables\Attachment>
 */
public function attachments(): array
{
    return [
        Attachment::fromStorage('/path/to/large.pdf')
                ->as('large.pdf')
                ->withMime('application/pdf'),
    ];
}

https://laravel.com/docs/11.x/mail#attaching-files-from-disk

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions