Jump to content

Zend Mail and embedded images


killboy

Recommended Posts

Hello everyone.For those who have used Zend Framework, I have the following issue:I've been playing around with Zend Mail, it's been very useful. It lets me set an HTML Body text and easy attachments. What I've not been able to do is to embed an image to an HTML email. Has anyone done so?Thanks.

Link to comment
Share on other sites

what if you put an absolute reference to the source in the <img> tag in the HTML mail? (I have no experience with Zend Mail, but just thought I'd throw that out).

Link to comment
Share on other sites

I don't know of any way to reference an image from the email itself as an image in an HTML body...Usually, images get downloaded from the site's servers, which is exactly why email clients block images by default.You may be able to use data URIs, but not all mail clients support it, so be sure to make some tests.And in either case, make sure you aren't relying on images - your mail should be readable even without them.

Link to comment
Share on other sites

Thanks for the replies guys.After a lot of Googling, I found what I needed. If someone has the same issue, here's the code:

// Controller$mail = new Zend_Mail();$mail->setFrom( "myEmail@example.com", "My Example" );$mail->setSubject( "My Subject" );$logo = $mail->createAttachment(	file_get_contents( APPLICATION_PATH . "/../public/img/myImage.png" ),	"image/png",	Zend_Mime::DISPOSITION_INLINE,	Zend_Mime::ENCODING_BASE64,	"myImage.png");$logo->id = "myLogo";

And the view:

<div align="center">	<img src="cid:myLogo" alt="My Logo">	</div>

Link to comment
Share on other sites

It's usually better to load images from a remote server in your emails, because clients will be able to download them faster.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...