Jump to content

Zend Mail and embedded images


killboy
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...