0

I want to display emails in my site, by using PHP imap. It works fine. But when I display the HTML- Body of the mail, the CSS rules destroy my site layout.

<div id="mail"><?php echo $mail->HTMLbody; ?></div>

I write a function, for looking and deleting the CSS rules in $mail->HTMLbody, it works but some of the CSS rules are necessary for the mail-layout.

I have only the idea, t look in the string and add infront of each rule '#mail', but I hpe there is better to do this. Have you any ideas?

Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41

2 Answers2

1

I think you answered your own question. Unless you want to load $mail inside of an iframe any CSS rules included in it will apply to the entire document. I would use the method you described and add #mail to the beginning of each CSS rule.

1

I would recommend using an iframe to display the emails because all the css in the iframe wont affect the rest of the site but still display the email properly. I would also recommend enabling sandbox on the iframe to prevent javascript executions. More info

Thaillie
  • 1,362
  • 3
  • 17
  • 31
  • I think you've nailed it. An `iframe` solves a lot of potential security problems too. – Geoff Atkins Oct 15 '15 at 08:29
  • @SebastianGl. Glad i could help, but i would like to reccomend you read into the `iframe` sandbox attribute to prevent some potential security hazards. – Thaillie Oct 15 '15 at 08:37