Jump to content

Displaying inline images in HTML email


beidlerj

Recommended Posts

 

Hello,

 

I am attempting to understand PHP's email functions and writing my own simple mail display script.  I have so far been able to snag the HTML part of email messages, but I'm having trouble with inline images contained in a message.  I can figure out which body part contains the image, and I can load the data from the message into a variable, decoding/converting as need be.  What I can't figure out, though, is how to get the image to display in the browser when I echo the HTML message body. 

 

Here's the way I've been approaching the problem thus far:

 

1. Use imap_fetchstructure to get info on a message.

2. Analyze the parts to find body part numbers for the HTML and the image(s).

3. Echo the HTML to the browser.

 

The HTML sent to the browser contains <img src="cid:bunchanumbers">.  How do I get the image to show up in that spot?

 

Thanks muchos,

 

Jeff

Link to comment
Share on other sites

If I simply output the file using readfile() or something like it, how does the web browser know that the data is for use as the cid:blahblah image?  I know I could use header() to add "Content-Type" image/whateveritis", "Content-Disposition: inline", etc., but what should I use in the "filename" parameter of "Content-Disposition"?  Would it be the actual name of the file, or the ID parameter, which is referenced in the HTML code (<img src="cid:blahblah">)?

 

Thanks, hope someone can help.  Much appreciated!

 

JEff

Link to comment
Share on other sites

Create a file, showimage.php or something like that. Bass the image name via get and pull the file from the db and for the img tag use this:

 

<img src="showimage.php?image=test.jpg" />

 

The showimage.php file should produce proper headers and use the readfile() command.

 

see www.php.net/headers not the user comments, as this has been done many times in there.

Link to comment
Share on other sites

Thanks for the reply.

 

Actually, I'm looking for a way to display messages that are read from an IMAP server, without needing to dismantle/store the various parts in a database.  Just read and display, like any ol' webmail.  I tried looking at the code for a few apps like SquirrelMail, but couldn't make heads or tails of it.  It's pretty complex.  I just want to do something very very simple, so I can understand how it works.

Link to comment
Share on other sites

I figured out what you were getting at, a couple days after the fact.  Must have been short on sleep then... :)

 

I was able to get images to display without storing them first.  Just did a simple show script that kicks out the content-type header and the image, but can be referenced in the <img> tag as the source... basically like returning a file, but just a stream of data.

 

Thanks for the help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.