Skip to content

Instantly share code, notes, and snippets.

@toolpixx
Last active February 27, 2019 18:50
Show Gist options
  • Save toolpixx/1b4b02d687aeb9993be9 to your computer and use it in GitHub Desktop.
Save toolpixx/1b4b02d687aeb9993be9 to your computer and use it in GitHub Desktop.
Simple attachment with symfony2 and swiftmailer without move attachment before...
...other stuff before....
/**
*
* use Symfony\Component\HttpFoundation\File\UploadedFile as UploadedFile;
*
* $message is instanceof \Swift_Message::newInstance()
* $enquiry is instanceof EnquiryEntity
* $enquiry->getAttachment() is the file-attribute for upload
*
*/
if ($enquiry->getAttachment() instanceof UploadedFile) {
$message->attach(
\Swift_Attachment::fromPath(
$enquiry->getAttachment()
)
->setFilename(
$enquiry->getAttachment()->getClientOriginalName()
)
->setContentType(
$enquiry->getAttachment()->getClientMimeType()
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment