Hi!

How can I include CSS styles in a PHP HTML Email?

This is what I have so far-

<?php


$msg='<html>This is a <em>test</em> message</html>';

mail('a@b.com', 'Test HTML Mail',$msg,"From: Santa Claus <santa@gmail.com>\n" .
    "MIME-Version: 1.0\n" .
    "Content-type: text/html; charset=iso-8859-1");
?>

Recommended Answers

All 2 Replies

Well firstly you need to create the email in the same format as you would any other HTML document. I.e. having a head, and body section.

In the head you should declare your stylesheets using absolute links, e.g. http://www.example.com/css/mycss.css or include the css style inline.

And with images, you'll need to declare them with absolute links, or by including the links as attachments.

R.

Thank you for your reply, but I have read that GMail will just strip off whatever is in the head if the email.

Anyways I found a work around by using inline styling.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.