PHP Classes

embedded images - cid

Recommend this page to a friend!

      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   Report abuse  
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   Report abuse  
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   Report abuse  
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
}