PHP Classes
Icontem

embedded images - cid


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP Email To DB   All threads   embedded images - cid   (Un) Subscribe thread alerts  
Subject:embedded images - cid
Summary:How do I treat an image embedded in an email as a CID
Messages:3
Author:Terrye Hoffman
Date:2009-11-05 00:00:20
Update:2009-11-06 13:22:37
 

  1. embedded images - cid   Reply  
Picture of Terrye Hoffman
Terrye Hoffman
2009-11-05 00:00:20
I don't know if anybody is monitoring this discussion...

This is such a great class, but some of the emails we get have an embedded jpg rather than text. For example, the person has embedded a picture of their newsletter rather than doing HTML. How can I make this jpg available? All that shows is something like this:

<img width=770 height=995
src="cid:image001.jpg@01C97FD1.C4D1DC70" align=left
alt="a bunch of text">

Any suggestions?

Thanks,
Terrye

  2. Re: embedded images - cid   Reply  
Picture of Terrye Hoffman
Terrye Hoffman
2009-11-06 13:20:56 - In reply to message 1 from Terrye Hoffman
I read some other posts and found a way to do it that works 98% of the time. Here's the code:

$MessageRev contains the text of the email

IF ( stristr($MessageRev, 'src="cid:') ) { // checks for any cid images
$pattern = '/src="cid:(.*?)"/si';
preg_match($pattern, $MessageRev, $out);
$needswork = $out[0]; // this is the string with the cid image as the source

$pattern2 = '/@(.*?)"/si';
preg_match($pattern2, $needswork, $out2); // this is the part to remove

$MessageRev = str_ireplace($out2[0],'"',$MessageRev);
$MessageRev = str_ireplace('src="cid:','src="http://www.domainname.com/attachmentfolder/'.$MessageID,$MessageRev); // this replaces the cid with the path to the saved attachment


  3. Re: embedded images - cid   Reply  
Picture of Terrye Hoffman
Terrye Hoffman
2009-11-06 13:22:37 - In reply to message 2 from Terrye Hoffman
I forgot the closing bracket in the code - here's the complete code:

IF ( stristr($MessageRev, 'src="cid:') ) { // checks for any cid images
$pattern = '/src="cid:(.*?)"/si';
preg_match($pattern, $MessageRev, $out);
$needswork = $out[0]; // this is the string with the cid image as the source

$pattern2 = '/@(.*?)"/si';
preg_match($pattern2, $needswork, $out2); // this is the part to remove

$MessageRev = str_ireplace($out2[0],'"',$MessageRev);
$MessageRev = str_ireplace('src="cid:','src="http://www.domainname.com/attachmentfolder/'.$MessageID,$MessageRev); // this replaces the cid with the path to the saved attachment
}

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products