private function SwiftMailer::attach in Swift Mailer 8
Same name and namespace in other branches
- 8.2 src/Plugin/Mail/SwiftMailer.php \Drupal\swiftmailer\Plugin\Mail\SwiftMailer::attach()
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 SwiftMailer::attach()
- SwiftMailer::attachAsMimeMail in src/
Plugin/ Mail/ SwiftMailer.php - Process MimeMail attachments.
- SwiftMailer::mail in src/
Plugin/ Mail/ SwiftMailer.php - Sends a message composed by drupal_mail().
File
- src/
Plugin/ Mail/ SwiftMailer.php, line 333
Class
- SwiftMailer
- Provides a 'Swift Mailer' plugin to send emails.
Namespace
Drupal\swiftmailer\Plugin\MailCode
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 (UrlHelper::isValid($file->uri, TRUE)) {
$content = file_get_contents($file->uri);
}
else {
$content = file_get_contents(\Drupal::service('file_system')
->realpath($file->uri));
}
$filename = $file->filename;
$filemime = $file->filemime;
// Attach file.
$m
->attach(Swift_Attachment::newInstance($content, $filename, $filemime));
}
}
}