59 lines
2.2 KiB
PHP
59 lines
2.2 KiB
PHP
<?php
|
|
|
|
class App_Model_Mail extends Zend_Mail
|
|
{
|
|
/**
|
|
* Sets the HTML body for the message
|
|
*
|
|
* @param string $html
|
|
* @param string $charset
|
|
* @param string $encoding
|
|
* @return Zend_Mail Provides fluent interface
|
|
*/
|
|
public function setBodyHtml($html, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE, $preload_images = true)
|
|
{
|
|
$preload_images = false;
|
|
try {
|
|
if ($preload_images) {
|
|
|
|
$this->setType(Zend_Mime::MULTIPART_RELATED);
|
|
|
|
$dom = new DOMDocument(null, $this->getCharset());
|
|
@$dom->loadHTML($html);
|
|
|
|
$images = $dom->getElementsByTagName('img');
|
|
|
|
for ($i = 0; $i < $images->length; $i++) {
|
|
$img = $images->item($i);
|
|
$url = $img->getAttribute('src');
|
|
|
|
$image_http = new Zend_Http_Client($url);
|
|
$image_http->setAdapter('Zend_Http_Client_Adapter_Curl');
|
|
|
|
$response = $image_http->request();
|
|
|
|
if ($response->getStatus() == 200) {
|
|
$image_content = $response->getBody();
|
|
|
|
$pathinfo = pathinfo($url);
|
|
$mime_type = $response->getHeader('Content-Type');
|
|
|
|
$mime = new Zend_Mime_Part($image_content);
|
|
$mime->id = $url;
|
|
$mime->location = $url;
|
|
$mime->type = $mime_type;
|
|
$mime->disposition = Zend_Mime::DISPOSITION_INLINE;
|
|
$mime->encoding = Zend_Mime::ENCODING_BASE64;
|
|
$mime->filename = $pathinfo['basename'];
|
|
|
|
$this->addAttachment($mime);
|
|
}
|
|
}
|
|
}
|
|
} catch (ZendException $e) {
|
|
Zend_Registry::get('error_log')->setEventItem('url', $this->getRequest()->getRequestUri())->setEventItem('trace', Zend_Json::encode($e->getTrace()))->setEventItem('params', Zend_Json::encode($this->getRequest()->getParams()))->info($e->getMessage());
|
|
}
|
|
|
|
return parent::setBodyHtml($html, $charset, $encoding);
|
|
}
|
|
} |