Link to home
Start Free TrialLog in
Avatar of sumachaa
sumachaa

asked on

Inlline attachments in HTML message

hi

i want to send and email in html format...
i'm using the phpmailer class to send emails....

the html message contains inline attachments also... like
<img src="c:\windows\image.gif"> or <td background="c:\dir\image.jpg">

i need the user whom i'm sending this mail also to view the image properly.. what should i do to make it happen....

thz
Sumesh
Avatar of jkna_gunn
jkna_gunn

are those images not available on the web?
when i send html emails i reference all images to my website

<img src="http://www.mysite.com/images/image.gif">
Avatar of sumachaa

ASKER

hi

it will definitely work if u give the web site adrs....

but what if I have an HTML file in my local system and i have to send this as my mail (not as an attachment...) and in that message we have different images which are local to my machine (not available thru a url)

When we sent a similiar message from Microsoft outlook.. they tackle this problem..... the local images are converted into some form like
<img src=cid:somevalue>

hope u got what i meant
 
Send yourself an e-mail in Microsoft Outlook with the image attached, then look at the raw contents of the message from the mailserver rather than looking at it through Outlook.  At least you'll be able to see how they do it.  Just beware that you may not be able to view the images on some other mail programs.  Best to do it using absolute URLs pointing to a server on the Internet - you're safer then.  Only downside is that Outlook 2003 will block these by default (although it tells the user so and gives them the option to download them).
ASKER CERTIFIED SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks a lot both.

as i pointed out above,
<< beware, the '\n' and '\r' are VERY tricky and each mailer has its own tolerance and/or may reject some legal code >> (darn bad guy shamelessly quoting himself)

... the codes has actually been in use for some time, but i don't have that many contacts with the folks it was developped for... and there is not too many exotic mailers in use with their custommers.

as far as i know, this works flawlessly using outlook as a reader (quite extensive testings) ; there also have been a few tests run on netscape and opera mailers ; plaintext mailers will behave like they should do which meens a perfect mess as there is no alternate text version in this case...

that said, everybody is free to use, modify, paste improovements (a lot c/should be done)... and perhaps give some feedback as to the results in various mailers...

please don't SPAM.

-------------

one last thing. i forgot to paste the function for CID creation.

function affich_image($image,$bordure="",$alt="image from site whatever"){global $CID;while($im=@func_get_arg($i)){$i++;
                  if(is_array($im)){$attributs=array_merge($attributs,$im);continue;}
                  if(substr($im,-5)!='.jpeg')$im.='.jpeg';
                  if(file_exists("../public/images/$im")){
                              if(is_array($attributs))foreach($attributs as $attribut=>$val)$attribs.=" $attribut=\"$val\"";
                              if(is_array($CID)){global $count_cid;$count_cid++;
                                    if(!$aff=array_search($im,$CID))$aff=$count_cid;
                                    $CID[$count_cid]=$im;echo"<img src=\"cid:$aff\"";}
                              
                              else echo"<img src=\"images/$im\" alt=\"$alt\" style=\"border : $bordure\"  $attribs>";return true;}}}

... takes an number of images names for input. (attributes may be added before and between images as array('attribute' => 'value', ...), priority given to the last array before the printed image.
... prints the html tag for the first availiable image in ;;/public/images (change as needed)
... store the image path in $CID instead if $CID is already declared as an array, and print the img tag subsequently

it seems there is something buggy in this version if the images were to be duplicated (check it out before you rely on this feature)

may also be a few ',' and quotes issues as i took out some of the code. (useless in this thraed + relied on other functions)

happy computing to all
I thought CID stand for something to do with the secret police in englands ?
hi, i've been a long time off the theads but this post may still be usefull to someone else

CID stands for content identifier and CIDs are the way to reference inline images in html mail.

see this excellent link http://mailformat.dan.info/headers/mime.html if you need clean and short but yet sufficiently detailed information.

<quote from the above link which i guess the author won't mind me to post>
The Content-ID header is primarily of use in multi-part messages (as discussed below); a Content-ID is a unique identifier for a message part, allowing it to be referred to (e.g., in IMG tags of an HTML message allowing the inline display of attached images). The content ID is contained within angle brackets in the Content-ID header.
</quote> .... see the site for more details and examples or use the above code.

see ya all

skull