private function SWIFTMailSystem::embed in Swift Mailer 7
Process inline images..
Parameters
Swift_Message $m: The message which inline images are to be added to.
array $images: The images which are to be added as inline images to the provided message.
1 call to SWIFTMailSystem::embed()
- SWIFTMailSystem::mail in includes/
classes/ SWIFTMailSystem.inc - Sends a message composed by drupal_mail().
File
- includes/
classes/ SWIFTMailSystem.inc, line 431 - 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 embed(Swift_Message $m, array $images) {
// Iterate through each array element.
foreach ($images as $image) {
if ($image instanceof stdClass) {
// Validate required fields.
if (empty($image->uri) || empty($image->filename) || empty($image->filemime) || empty($image->cid)) {
continue;
}
// Keep track of the 'cid' assigned to the embedded image.
$cid = NULL;
// Get image data.
if (valid_url($image->uri, TRUE)) {
$content = file_get_contents($image->uri);
}
else {
$content = file_get_contents(drupal_realpath($image->uri));
}
$filename = $image->filename;
$filemime = $image->filemime;
// Embed image.
$cid = $m
->embed(Swift_Image::newInstance($content, $filename, $filemime));
// The provided 'cid' needs to be replaced with the 'cid' returned
// by the Swift Mailer library.
$body = $m
->getBody();
$body = preg_replace('/cid:' . $image->cid . '/', $cid, $body);
$m
->setBody($body);
}
}
}