How to include a CSS file with HTML email that I am sending from a Perl CGI script?

I use the following code to create and send email through CGI perl. Images attach properly, but css files do not.

my $msg = new MIME::Lite( From => $from, To => $to_list, Subject => "My subject", Type => 'text/html', # 'multipart/mixed' Data => $body ); $msg->attach(Type => 'multipart/mixed', Path => $DOCS_URL . "/fonts-min.css"); $msg->attach(Type => 'multipart/mixed', Path => $DOCS_URL . "/eat.css"); $msg->attach(Type => 'multipart/mixed', Path => $DOCS_URL . "/site_styles2.css"); $msg->attach(Type => 'multipart/mixed', Path => $DOCS_URL . "/calendar_layout.css"); $msg->attach(Type => 'multipart/mixed', Path => $DOCS_URL . "/errnacc.css"); $msg->attach(Type => 'image/png', Path => $DOCS_URL . "/separator.gif"); $msg->attach(Type => 'image/png', Path => $DOCS_URL . "/trans_pixel.gif"); $msg->attach(Type => 'image/png', Path => $DOCS_URL . "/itg_side.gif"); $msg->send(); 

Images are attached properly, but css files are not connected at all. Any idea what "Type" should be used to attach CSS files? Or is there another problem?

+4
source share
6 answers

I believe text / css should be OK

+7
source

From my tests, many email clients simply remove all header elements before displaying an email message. Therefore, the use of external style sheets is not possible if you need to support a wide range of email clients.

My advice is to enable styling directly in HTML, as it hurts.

+6
source

I have to say that if you are trying to make your own script, it is sending an HTML letter, even if you get CSS files sent as attachments, this will not work.

The only way to do this with any certainty is to send HTML with all external files associated with absolute URLs. And even then it will not work as you expect.

+2
source

Try using the built-in css ... it works (see http://www.tizag.com/cssT/inline.php )

+2
source

I think that you already have your answer, but, in my opinion, a good way is, instead of directly placing the html code, use some html-based mail envelope containing the message and placeholders in a separate html file, and then parse and replace placeholders so that you can use CSS easily, and I think it will be easy to maintain.

0
source

just ran into the same problem. you can try this tool, http://templates.mailchimp.com/resources/inline-css/ do not forget to save a copy of the original template if you need to update

0
source

All Articles