当前位置: 动力学知识库 > 问答 > 编程问答 >

How do I include a CSS file with HTML email that I send from a Perl CGI script?

问题描述:

I am using following code to create and send email through CGI perl. The images get attached properly, but the 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();

The images get attached properly, but the css files are not attached at all.

Any idea what 'Type' should be used to attach CSS files?

Or is there any other problem?

网友答案:

I believe text/css should be OK

网友答案:

From my tests, many email clients simply remove all the head elements before displaying an email message. Therefore, using external style sheets isn't feasible if you have to support a wide range of email clients.

My advice is to include styling directly into the HTML, as painful as that is.

网友答案:

I have to say, if what you're trying to do with your script is send HTML-formatted email, even if you get the CSS files sent as attachments, it's not going to work.

The only way to do this with any confidence at all is to send HTML with all external files linked using absolute URLs. And even then it won't work the way you expect it to.

网友答案:

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

网友答案:

I think you already got your answer but in my opinion good way is, instead of putting html code directly, use some html based mail envelope having message and placeholders in 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 too.

网友答案:

just came across same issue. you may try this tool, http://templates.mailchimp.com/resources/inline-css/ remember to save the copy of original template in case you need to update

分享给朋友:
您可能感兴趣的文章:
随机阅读: