I'm creating a form that allows multiple files to be uploaded. The form field values and attachments are then to be emailed to certain address. I'm using Swiftmailer to generate these emails. I know how to attach a file with Swiftmailer, but I don't know how to attach multiple files. Does anybody know whether this is possible using Swiftmailer?
Asked
Active
Viewed 1.0k times
13
-
UPDATE: SwiftMailer [is being replaced](https://symfony.com/blog/the-end-of-swiftmailer) with [Symfony/Mailer](https://symfony.com/doc/current/mailer.html) – s3c Sep 08 '21 at 08:16
1 Answers
25
Yes, it's simply a matter of making multiple calls to attach()
:
$message->attach(Swift_Attachment::fromPath('../../uploads/hocuradit/' . $attPath . $attA));
$message->attach(Swift_Attachment::fromPath('../../uploads/hocuradit/' . $attPath . $attB));
Source: http://groups.google.com/group/swiftmailer/browse_thread/thread/416b287591dfe931?fwc=1

onteria_
- 68,181
- 7
- 71
- 64
-
1To supply an alternative file name to your attachment you can use: `$message->attach(Swift_Attachment::fromPath($filepath)->setFilename($mypreferredfilename))` – DeniseMeander Jul 17 '18 at 13:32