private function SwiftMailer::attachAsMimeMail in Swift Mailer 8
Same name and namespace in other branches
- 8.2 src/Plugin/Mail/SwiftMailer.php \Drupal\swiftmailer\Plugin\Mail\SwiftMailer::attachAsMimeMail()
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 SwiftMailer::attachAsMimeMail()
- SwiftMailer::mail in src/
Plugin/ Mail/ SwiftMailer.php - Sends a message composed by drupal_mail().
File
- src/
Plugin/ Mail/ SwiftMailer.php, line 371
Class
- SwiftMailer
- Provides a 'Swift Mailer' plugin to send emails.
Namespace
Drupal\swiftmailer\Plugin\MailCode
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, [
$file,
]);
}
else {
$m
->attach(Swift_Attachment::newInstance($a['filecontent'], $a['filename'], $a['filemime']));
}
}
}
}