Sending multiple attachment files by email I am trying to send multiple files attached to an email, but I can only make it work when only one file is attached. I am using mandrill mailer, btw.

Here is the code I have on a form submit:

    $attachments = [];
    if ($files) {
      foreach ($files as $key =&gt; $value) {
        $file = File::load($value['target_id']);
        $attachments[] = [
          'filepath' =&gt; $file-&gt;getFileUri(),
          'filename' =&gt; $file-&gt;getFileName(),
          'filemime' =&gt; $file-&gt;getMimeType(),
        ];
      }
    }

    $mailManager = \Drupal::service('plugin.manager.mail');
    $module = 'mymodule';
    $langcode = \Drupal::currentUser()-&gt;getPreferredLangcode();
    $params = [
      'subject' =&gt; 'Application from ' . $applying_user-&gt;get('field_first_name')-&gt;value . ' ' . $applying_user-&gt;get('field_last_name')-&gt;value,
      'candidate_name' =&gt; $applying_user-&gt;get('field_first_name')-&gt;value . ' ' . $applying_user-&gt;get('field_last_name')-&gt;value,
      'attachments' =&gt; $attachments,
    ];
    $mailManager-&gt;mail($module, 'email_application', $user_email, $langcode, $params);


Then using hook_mail():

 case 'email_application':
      $message['from'] = \Drupal::config('system.site')-&gt;get('mail');
      $message['subject'] = $params['subject'];
      $message['body'][] = buildBodyMail($params);
      $message['attachments'] = $params['attachments'];
      break;


The email I receive does not have any attachment, even though there are 4 files in this particular example meant to be attached.

If I change the code to:

    if ($files) {
      foreach ($files as $key =&gt; $value) {
        $file = File::load($value['target_id']);
        $attachments = [
          'filepath' =&gt; $file-&gt;getFileUri(),
          'filename' =&gt; $file-&gt;getFileName(),
          'filemime' =&gt; $file-&gt;getMimeType(),
        ];
      }
    }


...then it attaches only the last file of the set. It seems that 

$message['attachments']


does not allow a multidimensional array. I've seen examples with 

$message['params']['attachments'] = $params['attachments']; 


and have tried but to no avail.

How can multiple files be attached to an email? Thanks in advance.
Try as $message['attachments'][] instead of $message['attachments']
example
$message['attachments'][] = $params['attachment2'];