Skip to content

Commit

Permalink
FEATURE: Support SwiftMailer 6.x
Browse files Browse the repository at this point in the history
Previously the `EmailFinisher` threw an exception when using
attachments and a `swiftmailer/swiftmailer` version 6+:

    Call to undefined method Swift_Attachment::newInstance()

This is fixed with this change. Older SwiftMailer versions
are still supported.

Resolves: #112
  • Loading branch information
bwaidelich committed Jun 16, 2020
1 parent d2a7880 commit f1d2733
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Classes/Finishers/EmailFinisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* - carbonCopyAddress: Email address of the copy recipient (use multiple addresses with an array)
* - blindCarbonCopyAddress: Email address of the blind copy recipient (use multiple addresses with an array)
* - format: format of the email (one of the FORMAT_* constants). By default mails are sent as HTML
* - attachAllPersistentResources: if TRUE all FormElements that are converted to a PersistendResource (e.g. the FileUpload element) are added to the mail as attachments
* - attachAllPersistentResources: if TRUE all FormElements that are converted to a PersistentResource (e.g. the FileUpload element) are added to the mail as attachments
* - attachments: array of explicit files to be attached. Every item in the array has to be either "resource" being the path to a file, or "formElement" referring to the identifier of an Form Element that contains the PersistentResource to attach. This can be combined with the "attachAllPersistentResources" option
* - testMode: if TRUE the email is not actually sent but outputted for debugging purposes. Defaults to FALSE
*/
Expand Down Expand Up @@ -209,7 +209,7 @@ protected function addAttachments(SwiftMailerMessage $mail)
if ($this->parseOption('attachAllPersistentResources')) {
foreach ($formValues as $formValue) {
if ($formValue instanceof PersistentResource) {
$mail->attach(\Swift_Attachment::newInstance(stream_get_contents($formValue->getStream()), $formValue->getFilename(), $formValue->getMediaType()));
$mail->attach(new \Swift_Attachment(stream_get_contents($formValue->getStream()), $formValue->getFilename(), $formValue->getMediaType()));
}
}
}
Expand All @@ -227,7 +227,7 @@ protected function addAttachments(SwiftMailerMessage $mail)
if (!$resource instanceof PersistentResource) {
continue;
}
$mail->attach(\Swift_Attachment::newInstance(stream_get_contents($resource->getStream()), $resource->getFilename(), $resource->getMediaType()));
$mail->attach(new \Swift_Attachment(stream_get_contents($resource->getStream()), $resource->getFilename(), $resource->getMediaType()));
}
}
}
Expand Down

0 comments on commit f1d2733

Please sign in to comment.