-3

Is there a way to include a complete stylesheet within the email using PHPs mail() function to ensure the proper display of styles? I have a large stylesheet, specifically for CKEditor, that I need to include to ensure the correct styling in the email.

EDIT

I know that I could just copy the styles into an inline <style> tag. However, the CKEditor Style Sheet alone has over 10k lines, so I wouldn't think copying and pasting 10k lines is a good solution. So maybe there is another clever way to do this.

Edit 2: Solution

Using file_get_contents('xyz.css') is the solution I was looking for. It loads the content of the .css-file and I can simply wrap it with <style> and it works.

Gykonik
  • 638
  • 1
  • 7
  • 24
  • 1
    Possible duplicate of [How can I send HTML mails with included CSS with PHPMailer?](http://stackoverflow.com/questions/358788/how-can-i-send-html-mails-with-included-css-with-phpmailer) – Chris G Jan 25 '16 at 18:47
  • 1
    Not really... Most of the links are outdated, etc... How can I include a stylesheet, if I don't want to link the absolute path?... – Gykonik Jan 25 '16 at 18:57
  • 1
    Simple: you shouldn't as most email clients will reject/ignore/throw out any stylesheet. Use inlined CSS. – Funk Forty Niner Jan 25 '16 at 19:09
  • @ChrisG that's not a good link for a dupe and as the OP stated, it's out of date and the accepted answer in there should be modified or deleted http://stackoverflow.com/a/358825/ – Funk Forty Niner Jan 25 '16 at 19:17
  • I know i should use inlined CSS, but I can't do this for over 10.000 lines of Code (CKEditor Style Sheet)... – Gykonik Jan 25 '16 at 19:30
  • @Fred-ii-: Sorry man, just trying to be helpful. Where is the love??? Gykonik: Sorry, just trying to be helpful – Chris G Jan 25 '16 at 19:53
  • well you have no choice. You should have thought about this before starting your project. – Funk Forty Niner Jan 25 '16 at 20:01
  • But... But... :c Is there any way, how to get the data from the stylesheets and paste them into -Tags? – Gykonik Jan 25 '16 at 20:04

3 Answers3

0

As I know you have these options

  1. Add Internal Style Sheet
  2. Inline Styles
  3. Or upload the css file to your host and share the like in email.

Not a best answer. Just For Your Information(FYI)

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

Email template styles are very sensitive, that is, there are many more email clients than web browsers and they all display code differently.

If you have a stylesheet that's worth thousands of lines, you unfortunatly won't be able to simply include an external stylesheet and expect things to look uniform between different email clients.

Your best bet is to start the template from scratch using a boilerplate template and recreate the stylesheet rules the best you can.

EDIT: simple email template boilerplate to start https://github.com/seanpowell/Email-Boilerplate

mehring
  • 11
  • 2
0

That duplicate question is not outdated - everything in it is still true. The way you include styles in email (what you asked) has not changed at all - what styles you put in may have, but that's a different question. I'd suggest you look at an email CSS framework like Zurb's Foundation for email.

Synchro
  • 35,538
  • 15
  • 81
  • 104