Skip to content

Conversation

rodrigopedra
Copy link
Contributor

Closes #55983

Currently, there is no straightforward way to attach an UploadedFile instance to a mailable.

That is useful on contact forms that only forwards a form to an email.

Attachment::fromData() can be used, but:

  • Requires the attachment name to be set manually by the developer
  • Requires the developer to remember calling $file->get() to retrieve the uploaded file's content
  • Does not set the attachment's mime type from the original file

This PR:

  • Adds a new helper Attachment::fromUploadedFile(), which creates an Attachment instance from an UploadedFile instance, and sets its name from the UploadedFile original client name, and sets it mime-type from the inferred mime-type, or from the client mime-type.
  • Adds a corresponding test case

@taylorotwell taylorotwell merged commit 49c617e into laravel:12.x Jun 13, 2025
60 checks passed
@rodrigopedra rodrigopedra deleted the issue-55983 branch June 13, 2025 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow UploadedFile instance in mail attachments
2 participants