You are here

private function SWIFTMailSystem::attach in Swift Mailer 7

Process attachments.

Parameters

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

array $files: The files which are to be added as attachments to the provided message.

2 calls to SWIFTMailSystem::attach()
SWIFTMailSystem::attachAsMimeMail in includes/classes/SWIFTMailSystem.inc
Process MimeMail attachments.
SWIFTMailSystem::mail in includes/classes/SWIFTMailSystem.inc
Sends a message composed by drupal_mail().

File

includes/classes/SWIFTMailSystem.inc, line 350
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 attach(Swift_Message $m, array $files) {

  // Iterate through each array element.
  foreach ($files as $file) {
    if ($file instanceof stdClass) {

      // Validate required fields.
      if (empty($file->uri) || empty($file->filename) || empty($file->filemime)) {
        continue;
      }

      // Get file data.
      if (valid_url($file->uri, TRUE)) {
        $content = file_get_contents($file->uri);
      }
      else {
        $content = file_get_contents(drupal_realpath($file->uri));
      }
      $filename = $file->filename;
      $filemime = $file->filemime;

      // Attach file.
      $m
        ->attach(Swift_Attachment::newInstance($content, $filename, $filemime));
    }
  }
}