Skip to content

Commit

Permalink
Merge pull request #12 from ByteParty/fix-file-count
Browse files Browse the repository at this point in the history
send more than one file
  • Loading branch information
Alexander Bigga authored Nov 26, 2021
2 parents fa88632 + 4c7a86a commit 11bc699
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Classes/Controller/EmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public function createAction(\Slub\SlubForms\Domain\Model\Email $newEmail, array

$form = $this->formsRepository->findAllById($newEmail->getForm())->getFirst();

$fileNames = [];

// walk through all fieldsets
foreach($fieldParameter as $getfieldset => $getfields) {

Expand Down Expand Up @@ -211,6 +213,7 @@ public function createAction(\Slub\SlubForms\Domain\Model\Email $newEmail, array
$_FILES['tx_slubforms_sf']['tmp_name']['field'][$getfieldset][$field->getUid()],
$fileName
);
$fileNames[] = $fileName;
} else {

$content[$field->getTitle()] = '-';
Expand Down Expand Up @@ -341,14 +344,16 @@ public function createAction(\Slub\SlubForms\Domain\Model\Email $newEmail, array
array( 'email' => $newEmail,
'form' => $form,
'content' => $content,
'filename' => $fileName,
'filenames' => $fileNames,
'settings' => $this->settings,
)
);

// remove $filename from uploads-directory
if (!empty($fileName)) {
unlink($fileName);
// remove $fileNames from uploads-directory
if (!empty($fileNames)) {
foreach ($fileNames as $fileName) {
unlink($fileName);
}
}

}
Expand Down Expand Up @@ -455,8 +460,11 @@ protected function sendTemplateEmail(array $recipient, array $sender, $subject,
// HTML Email
$message->addPart($emailTextHTML, 'text/html');

if (!empty($variables['filename']))
$message->attach(\Swift_Attachment::fromPath($variables['filename']));
if (!empty($variables['filenames'])){
foreach ($variables['filenames'] as $fileName) {
$message->attach(\Swift_Attachment::fromPath($fileName));
}
}

$message->send();

Expand Down

0 comments on commit 11bc699

Please sign in to comment.