contao/import — Issue #2595: Support BODY Background images in E-mail sending
Author: importer
Created: 2011-11-29 19:50:11+00:00
State: open
Labels: Accepted, Feature, framework

Hi leo

currently you only replace src="" images in e-mail messages, however, due to the nonsense that Outlook is still a large e-mail client, it doesn't allow any css to use background image, unless specified directly on the BODY tag. I've added a duplicate of your code (for simplicity) to allow this to happen.

```
// Find background images
$arrMatches = array();
preg_match_all('/background="([^"]+\.(jpe?g|png|gif|bmp|tiff?|swf))"/Ui', $this->strHtml, $arrMatches);
$strBase = Environment::getInstance()->base;

// Embed internal images
foreach (array_unique($arrMatches[1]) as $url)
{
// Try to remove the base URL
$src = str_replace($strBase, '', $url);

// Embed the image if the URL is now relative
if (!preg_match('`^https?://`', $src) && file_exists($this->strImageDir . $src))
{
$cid = $this->objMessage->embed(Swift_EmbeddedFile::fromPath($this->strImageDir . $src));
$this->strHtml = str_replace('background="' . $url . '"', 'background="' . $cid . '"', $this->strHtml);
}
}

```

--- _Originally created by thyon on October 3rd, 2010, at 02:13am (ID 2595)_