Skip to content

[12.x] add Attachment::fromUploadedFile method #56027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 13, 2025

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