Welcome Guest, Not a member yet? Register   Sign In
Email class - missing Content-ID header

Hello developers,

I have sent some email with CI Email class, there were html emails with plain text part, and inline attachments - and nothing else.
When CI made the email, it didn't set the "Content-ID" MIME header (according to rfc 2045: http://www.ietf.org/rfc/rfc2045.txt, section 7).

Looks like couldn't insert that with extending the class, I just patched the original source (I didn't find any instruction about how could I send patch), here is it:
diff -crB  _Email.php.ORIG Email.php
*** _Email.php.ORIG     2009-03-19 21:34:15.000000000 +0100
--- Email.php   2009-03-19 21:38:01.000000000 +0100
*** 1123,1128 ****
--- 1123,1132 ----
                        $h .= "name=\"".$basename."\"".$this->newline;
                        $h .= "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline;
                        $h .= "Content-Transfer-Encoding: base64".$this->newline;
+                       if ($this->_attach_disp[$i] === "inline")
+                       {
+                               $h .= "Content-ID: <".$basename.">".$this->newline;
+                       }
                        $attachment[$z++] = $h;
                        $file = filesize($filename) +1;

Hope this help.


hi airween,

welcome to CI. great post! two things:

1) this should also be in the feature requests forum so that CI devs will look at it as a possible inclusion. it's been suggested before in the RichMail lib on wiki, and it's a worthwhile improvement.
2) i think it should be included, but some things need to be updated...

attachments can be disposition=inline without a content id. using "inline" as disposition just tells the email client that the sender prefers that the attachment be rendered inline with the rest of the message. it is not a specification that there needs to be a corresponding cid. also, $basename is not an ideal cid - generally it would be some kind of encoded version of the filename so that there is less risk of inserting some garbage another email client can't read. in the case of cids in HTML img tags, the same encoded cid could be generated outside the Email.php class as well.

AFAICT, the richmail lib simply uses the attachment number for the cid. also, it puts the filename=$basename as an attribute to the Content-Disposition header.


hello sophistry,

thanks for reply,

1) as I wrote I'm new in CI and in these forums too - I didn't know where must I post this message. I just searched the word "Email" but I didn't get any answer, so the RichMail lib is new for me but it's interesting - I'll see that.
2) yes, I know it's "generally optional", but it's just my experience, most email client can't render correctly the html part of message without it (I have used a self-developed junk-mailer for newsletters, written in Python).
You're right, content-id doesn't need to have $basename, and what is more RFC decribes it must be world-unique, but it's more confortable to use.

thanks again,


Theme © iAndrew 2016 - Forum software by © MyBB