Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: zend mailer dołączenie obrazków
Forum PHP.pl > Forum > Gotowe rozwiązania
pogdan
Jest kod poniżej który ładnie wysyła maila HTML. Wyciąga i dołącza obrazki też bardzo ładnie. Natomiast nie wyświetla tych obrazków w tresci maila. Próbuję coś takiego

  1. //$mime->id = 'cid_'.md5_file($url);//generate a unique CID
  2. //$this->setBodyHtml(str_replace("/$file",'cid:'.$at->id,$this->getBodyHtml(true)),'UTF-8',Zend_Mime::ENCODING_8BIT);
  3.  
  4. $html = str_replace($url, 'cid:'.$pathinfo['basename'] ,$html);


ale to nie idzie : ( może ktoś ma doświadczenie z tym. Obrazki w poczcie są ale się nie podstawiają : (


  1. require_once 'Zend/Loader.php';
  2. require_once 'Zend/Http/Client.php';
  3. require_once 'Zend/Mail.php';
  4.  
  5. class Techi_Mail extends Zend_Mail
  6. {
  7.  
  8. /**
  9.   * Sets the HTML body for the message
  10.   *
  11.   * @param string $html
  12.   * @param string $charset
  13.   * @param string $encoding
  14.   * @return Zend_Mail Provides fluent interface
  15.   */
  16. public function setBodyHtml($html, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE, $preload_images = true)
  17. {
  18. if ($preload_images)
  19. {
  20. $this->setType(Zend_Mime::MULTIPART_RELATED);
  21.  
  22. $dom = new DOMDocument(null, $this->getCharset());
  23. @$dom->loadHTML($html);
  24.  
  25. $images = $dom->getElementsByTagName('img');
  26.  
  27. for ($i = 0; $i < $images->length; $i++)
  28. {
  29. $img = $images->item($i);
  30. $url = $img->getAttribute('src');
  31.  
  32. $image_http = new Zend_Http_Client($url);
  33. $response = $image_http->request();
  34.  
  35. if ($response->getStatus() == 200)
  36. {
  37. $image_content = $response->getBody();
  38.  
  39. $pathinfo = pathinfo($url);
  40. $mime_type = $response->getHeader('Content-Type');
  41.  
  42. $mime = new Zend_Mime_Part($image_content);
  43. $mime->id = $url;
  44. $mime->location = $url;//pathinfo['basename'];
  45. $mime->type = $mime_type;
  46. $mime->disposition = Zend_Mime::DISPOSITION_INLINE;
  47. $mime->encoding = Zend_Mime::ENCODING_BASE64;
  48. $mime->filename = $pathinfo['basename'];
  49.  
  50. //$mime->id = 'cid_'.md5_file($url);//generate a unique CID
  51. //$this->setBodyHtml(str_replace("/$file",'cid:'.$at->id,$this->getBodyHtml(true)),'UTF-8',Zend_Mime::ENCODING_8BIT);
  52.  
  53. $html = str_replace($url, 'cid:'.$pathinfo['basename'] ,$html);
  54. $this->addAttachment($mime);
  55. }
  56. }
  57. }
  58. //dd($html);
  59. return parent::setBodyHtml($html, $charset, $encoding);
  60. }
  61. }
nospor
Z tego co na szybko spojrzalem to identyfikatorem obrazka jest ID a nie FILENAME. WIec do CID masz przekazywac ID a nie FILENAME
pogdan
czyli tak?
  1. $html = str_replace($url, 'cid:'.md5($mime->id) ,$html);


Nie idzie : ( . ( Czemu zend nie mógł tego zrobić w swojej wpasionej bibliotece. )
nospor
facepalmxd.gif

$mime->id - to jest ID
md5($mime->id) - to jest md5 z ID....

Czego nie rozumiesz w zdaniu: Masz tam wstawic ID.
Czy ja napisalem: masz tam wstawic md5 z ID? Nie ja napisalem: masz tam wstawic ID....
pogdan
racja!!!! Dzięki!!!!!

Ładnie chodzi dzięki jeszcze raz.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.