Guest User

Untitled

a guest
Aug 30th, 2018
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. When using PEAR's Mail_Mime, the text portion doesn't work when attaching HTML images
  2. //Headers
  3. $headers['From'] = "from@address.com";
  4. $headers['To'] = "to@address.com";
  5. $headers['Subject'] = "A MIME Email";
  6.  
  7. //Text Portion
  8. $text = "This is the text portion.";
  9.  
  10. //HTML Portion
  11. $html = "<html><body><p><img src='image.png' />This is the HTML portion.</p></body></html>";
  12.  
  13. //Set up the MIME email
  14. $mime = new Mail_mime(array('eol' => "rn"));
  15. $mime->setTXTBody($text);
  16. $mime->setHTMLBody($html);
  17. $mime->addHTMLImage("/path/to/image.png", "image/png");
  18.  
  19. //Prepare the message to be sent
  20. $body = $mime->get();
  21. $headers = $mime->headers($headers);
  22.  
  23. //Send the message via SMTP
  24. $mail_obj =& Mail::factory('smtp', array('host' => 'smtp.server.com', 'port' => 25));
  25. $mail_obj->send("to@address.com", $headers, $body);
  26.  
  27. Date: Thu, 26 May 2011 10:39:24 -0500 (CDT)
  28. From: From Address <from@address.com>
  29. Subject: A MIME Email
  30. To: to@address.com
  31. Message-id: <20110526153924.0C12120697@smtp.server.com>
  32. MIME-version: 1.0
  33. Content-type: multipart/alternative;
  34. boundary="=_e107860f353617028a0059317ce51c1f"
  35. Original-recipient: rfc822;to@address.com
  36.  
  37. --=_e107860f353617028a0059317ce51c1f
  38. Content-Transfer-Encoding: quoted-printable
  39. Content-Type: text/plain;
  40. charset=ISO-8859-1
  41.  
  42. This is the text portion.
  43. --=_e107860f353617028a0059317ce51c1f
  44. Content-Type: multipart/related;
  45. boundary="=_52fd7475fcf0abd310b6a38cd33f5c46"
  46.  
  47. --=_52fd7475fcf0abd310b6a38cd33f5c46
  48. Content-Transfer-Encoding: quoted-printable
  49. Content-Type: text/html;
  50. charset=ISO-8859-1
  51.  
  52. <html><body><p><img src='cid:3c0db5d0a50b8752771f64048f527338' />This is th=
  53. e HTML portion.</p></body></html>
  54.  
  55. --=_52fd7475fcf0abd310b6a38cd33f5c46
  56. Content-Transfer-Encoding: base64
  57. Content-ID: <3c0db5d0a50b8752771f64048f527338>
  58. Content-Type: image/png;
  59. name=background.png
  60. Content-Disposition: inline;
  61. filename=background.png
  62.  
  63. iVBORw0KGgoAAAANSUhEUgAAAAEAABOICAYAAABwnAfKAAAAkUlEQVR42u3WSwrAIAwFwND7X9d1
  64. eoHSb9TSzmYQSV5AXCRaa7lEROySJ+8uFd+8q2l73FEdkJNSRgR07q0uuVncJWBY6I9OWy85bKRB
  65. 7xo04TN8/vTO0OriziWFvcMCJqTMCui8rj5fuyMz43i1BwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  66. AAAAAAAAAIB/swItzir5J/ImiQAAAABJRU5ErkJggg==
  67. --=_52fd7475fcf0abd310b6a38cd33f5c46--
  68.  
  69. --=_e107860f353617028a0059317ce51c1f--
Add Comment
Please, Sign In to add comment