How to mail HTML/CSS output as attachment?


Tags: php,css,email,pdf-generation

Problem :

I contribute to a business software suite with a backend coded in PHP. Our client has made the request that our reports as we know them -- full of charts, tables, visual flourishes -- be emailable. They will schedule a time for certain mails to go off on a per-user basis and it will run a report with the options they desire, then essentially copy what's been output and mail them.

We do something like this already, but it's a very exhaustive process to teach these reports how to go from the screen to email; floating divs are a mess, various styles broken by Outlook 2007.

I'm inquiring on how to take the output and save it as something attachable to the email. That would be their report. Presently we just print out an HTML email directly from the cron-run PHP file.

I've looked into PDF converters and they will probably not work out; we can live without charts, but a lot of our styling won't be interpreted correctly by the PDF. The ideal product is one that would "screenshot" our output and save it as a JPG, if such a thing is possible to exist. My question is basically, does anyone know how to save us tons of work for a better product by putting output into a JPG? I know it has to be rendered from the browser, it's probably a silly notion but hopefully someone can lead me in the right direction.



Solution :

In my personal experience, as i've done this for our platform, we generate the html as a regular page and then email it, taking care of using relative paths for images, and then using PHPMailer for sending it through a SMTP server.

We send the reports as the main mail body, not as an attachment.

As an additional hint, we use Javascript libraries for the charts, and as an intermediate step, render the charts as PNG via CasperJS, that way we can develop very good looking charts in Chrome/Firefox, and then render those statically for sending via email.


    CSS Howto..

    How can I fix an element to the page that is of a variable distance from the edge of the screen?

    how to remove small space that only appear in iphone browser

    Background images: how to fill whole div if image is small and vice versa

    How can I apply CSS to a JPG server-side?

    How to find number of style classes defined in a CSS file

    How to select all a pseudo-classes in CSS?

    How can I move all my CSS box shadows back under div

    How to change CSS styling from within Angular 2 Component

    sencha touch 2.0 : How to apply conditional background color to list item

    how do I create unique looking angular ui bootstrap dialogs

    How to inspect precompiled minified SASS code

    How to only underline text element inside an element in CSS?

    How to prevent division when using variables separated by a slash in CSS property values

    How do I create a class hierarcy in CSS for MVC4 Razor?

    How to create a single space in css between a sentence and a photo on my wordpress site?

    How to apply custom styles to a jasper html report

    How to avoid this overlapping in plain CSS?

    How to specify multiple hover event targets in CSS?

    I want to override some CSS that says border:none to have border bottom. How can I do this?

    How to put the div at the center with css?

    CSS: overlay looks fine on Chrome, but not in Firefox 3: how do I fix the vertical offset?

    How to order list which produce result that starts from 1.1, 1.2, 1.3 (instead of just 1, 2, 3) with css and html

    How to fix the shadow on my menu, Fiddle example shown

    How change css using variables to make an animation

    How to wrap entire line with overline and underline , until the end of the line ?

    How to target all divs of the same class except for hovered over div?

    How to use “Monotype Corsiva” font in CSS statement?

    Block grid shows horizontal scroll bar in Foundation

    Markup/Style best practices: How to efficiently distribute style rules over CSS classes?

    how do I select second submit button to imply other color