Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> zend mailer dołączenie obrazków
pogdan
post 8.10.2014, 06:58:35
Post #1





Grupa: Zarejestrowani
Postów: 68
Pomógł: 0
Dołączył: 21.10.2007

Ostrzeżenie: (0%)
-----


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. }
Go to the top of the page
+Quote Post
nospor
post 8.10.2014, 07:01:53
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Z tego co na szybko spojrzalem to identyfikatorem obrazka jest ID a nie FILENAME. WIec do CID masz przekazywac ID a nie FILENAME


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pogdan
post 8.10.2014, 07:22:47
Post #3





Grupa: Zarejestrowani
Postów: 68
Pomógł: 0
Dołączył: 21.10.2007

Ostrzeżenie: (0%)
-----


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. )
Go to the top of the page
+Quote Post
nospor
post 8.10.2014, 07:26:46
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




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....


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pogdan
post 8.10.2014, 07:59:47
Post #5





Grupa: Zarejestrowani
Postów: 68
Pomógł: 0
Dołączył: 21.10.2007

Ostrzeżenie: (0%)
-----


racja!!!! Dzięki!!!!!

Ładnie chodzi dzięki jeszcze raz.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 27.06.2025 - 18:46