You are here

private function SWIFTMailSystem::attachAsMimeMail in Swift Mailer 7

Process MimeMail attachments.

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 SWIFTMailSystem::attachAsMimeMail()
SWIFTMailSystem::mail in includes/classes/SWIFTMailSystem.inc
Sends a message composed by drupal_mail().

File

includes/classes/SWIFTMailSystem.inc, line 388
The implementation of MailSystemInterface which delegates handling of e-mails to the Swift Mailer library.

Class

SWIFTMailSystem
@file The implementation of MailSystemInterface which delegates handling of e-mails to the Swift Mailer library.

Code

private 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, array(
          $file,
        ));
      }
      else {
        $m
          ->attach(Swift_Attachment::newInstance($a['filecontent'], $a['filename'], $a['filemime']));
      }
    }
  }
}