Messages with file attachments fail to send

Created on 18 May 2022, over 2 years ago
Updated 17 April 2023, over 1 year ago

Form submissions with file attachments fail to send and trigger an exception.

Steps to reproduce:
- Create a webform with a file upload element
- Configure that webform to send out submissions with uploaded files as attachments on the submission email
- Fill out the webform with an uploaded file

The following error will appear:

TypeError: file_exists(): Argument #1 ($filename) must be of type string, array given in file_exists()
(line 143 in .../postmark/src/Plugin/Mail/PostmarkMail.php)

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany igel

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡±Netherlands Rop Rotterdam

    I think a better way would be to use the Postmark\Models\PostmarkAttachment; within PostmarkMail.php

    use Postmark\Models\PostmarkAttachment;

    add something like this:

    // Make sure the files provided in the attachments array exist.
        if (!empty($message['params']['attachments'])) {
          $attachments = $this->convertAttachmentsToPostmarkObjects($message['params']['attachments']);
    
          if (count($attachments) > 0) {
            $postmark_message['attachments'] = $attachments;
          }
        }
    protected function convertAttachmentsToPostmarkObjects($attachments){
        $postmark_attachments = [];
        foreach ($attachments as $attachment) {
          if (file_exists($attachment['filepath'])) {
            $postmark_attachments[] = PostmarkAttachment::fromFile($attachment['filepath'], $attachment['filename'], $attachment['filemime']);
          }
        }
        return $postmark_attachments;
      }
  • πŸ‡ΊπŸ‡ΈUnited States mralexho

    Ran into this issue today. Created a patch from #3 πŸ› Messages with file attachments fail to send Needs review comments. Attachments are working successfully now.

Production build 0.71.5 2024