You are here

protected function SwiftMailer::attachAsMimeMail in Swift Mailer 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Mail/SwiftMailer.php \Drupal\swiftmailer\Plugin\Mail\SwiftMailer::attachAsMimeMail()

Process MimeMail attachments.

@internal

Parameters

\Swift_Message $m: The message which attachments are to be added to.

array $attachments: The attachments which are to be added message.

1 call to SwiftMailer::attachAsMimeMail()
SwiftMailer::mail in src/Plugin/Mail/SwiftMailer.php
Sends a message composed by drupal_mail().

File

src/Plugin/Mail/SwiftMailer.php, line 397

Class

SwiftMailer
Provides a 'Swift Mailer' plugin to send emails.

Namespace

Drupal\swiftmailer\Plugin\Mail

Code

protected function attachAsMimeMail(Swift_Message $m, array $attachments) {

  // Iterate through each array element.
  foreach ($attachments as $a) {
    if (is_array($a)) {

      // Validate that we've got either 'filepath' or 'filecontent.
      if (empty($a['filepath']) && empty($a['filecontent'])) {
        continue;
      }

      // Validate required fields.
      if (empty($a['filename']) || empty($a['filemime'])) {
        continue;
      }

      // Attach file (either using a static file or provided content).
      if (!empty($a['filepath'])) {
        $file = new stdClass();
        $file->uri = $a['filepath'];
        $file->filename = $a['filename'];
        $file->filemime = $a['filemime'];
        $this
          ->attach($m, [
          $file,
        ]);
      }
      else {
        $m
          ->attach(new Swift_Attachment($a['filecontent'], $a['filename'], $a['filemime']));
      }
    }
  }
}