Question

I have a PHPMailer script that sends an HTML Email (via the code to embed a HTML file). The HTML file is a Bootstrap 3 page that references external CSS files for the bootstrap styling.

The Email works, and is received with images etc., but without any of the CSS. Is there anything special I need to do, or is it not recommended?

There is a similar question here: How can I send HTML mails with included CSS with PHPMailer? but as it's 4 years old, I thought perhaps things may have changed..?!

If not then I guess I'll have to reformat the Email to be HTML only without CSS.

Was it helpful?

Solution

Trizz & Carrie are correct -- most email clients that I'm aware of will block external scripts/stylesheets so your best bet is to include the styles you need at the top of the body of the HTML email.

<style type="text/css">

.some_class {
  /*styles here*/
}

.another_class {
  /*styles here*/
}

</style>

<!--now start your html for your email here-->

It's also best practice to give your style classes and ids really unique names to avoid conflict with built-in CSS naming conventions of various email platforms. You can test your code against a variety of email programs with a service like Email on Acid (although this one is not free).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top