beidlerj Posted July 10, 2007 Share Posted July 10, 2007 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 Quote Link to comment Share on other sites More sharing options...
beidlerj Posted July 11, 2007 Author Share Posted July 11, 2007 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 Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
beidlerj Posted July 11, 2007 Author Share Posted July 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
beidlerj Posted July 13, 2007 Author Share Posted July 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.