开发者

Having trouble sending an Excel (converted to HTML/PHP) doc to Email via mail() function

I converted an Excel spreadsheet to PHP (using save as HTML to convert .xls to "round trip" HTML) so that I could fill in the spreadsheet with data that was filled in using an HTML form and stored in a database. This part of the project is working fine (although it still needs to be improved).

Unfortunately I've run into two problems (but they are related to each other). First, when I converted the document to HTML it created a lot of CSS - which is needed so that the HTML document looks identical to the original Excel document when viewed or printed. The problem is the CSS bloats the code terribly. So is there a way to move all that CSS to an external style sheet and still reference it when I send the code via the mail() function? Which leads me to my second question.

Here's a link to the code in jsfiddle:

http://jsfiddle.net/tyleryoungblood/KzzWR/

And here's what it looks like rendered (Note: none of the data is filled in because it can't connect to the database, and even if it could PHP code isn't rendered in jsfiddle):

http://jsfiddle.net/tyleryoungblood/KzzWR/embedded/result/

How do I send all this code via email so that the receiver of the email gets the code as an attached document? Preferably the document would be converted back into a working excel document, but I realize that might be a stretch. So an attached HTML or PHP page (that looks exactly like the original Excel doc) that is both viewable and printable would also be an acceptable final format. I'd prefer the HTML be included as an attached document rather than rendered directly inside the email开发者_开发技巧.

The goal is to convert the accounting department's antiquated expense system from a paper-based system into an electronic system. Currently employees have to fill out an excel spreadsheet with their mileage and expenses, print it and mail it to accounting. I'm trying to upgrade that process so that an employee fills in their expenses on a web page and then send the form electronically by hitting "submit to accounting". Normally I'd just send the values of the form in the email (like you do with a contact form), but accounting doesn't want to change their record keeping system. They want the data to look identical to the way it's always looked - like a printed excel spreadsheet. That's why I've created a PHP version of the excel page that auto-populates (via a database that was populated via an HTML form). Now I just need to figure out how it can be emailed directly to accounting.

Thanks in advance for the help!


Technically an email attachment is just a part of the email data that's separated from the rest by a MIME content boundary and has its own headers. I'm sure there's some php library that'll help with all of that (unfortunately, I don't know one right off the bat, but it must exist).

You can check out an email's structure in your email client - there's usually an option to "view raw source" or something similar. You'll usually see the email's own content as both html and plain text (the first 2 MIME sections), and if there are any attachments, they'll be in the following sections.

In any case, if you want to send accounting something that's not meant to be edited, and looks like a printed document, then I'd say you should go with a PDF file instead. That's what PDF is for, after all. Alternatively, you could use HTML with an external CSS file as the content of the email itself. Then accounting will simply see the sheet directly in their email client, without having to open an attachment in Excel.

If you do want an attachment, and it has to open in Excel, I'd go with XML instead of HTML. Excel can export to XML since that's simply a representation of data, whereas HTML involves a bit more shoehorning everything into an HTML-way of doing things. Also, I don't know if Excel can figure out opening an HTML file with an external CSS file.

If you want to go the XML route, you can do this: Save your Excel file as XML, and take a look at the file's contents. There'll still be a lot of extra data in there, but a lot of it serves no purpose, so see how much you can rid of until Excel won't open correctly it anymore. Then you have a nice template to work with. It's not too hard to figure out how it all goes together. In the end, you should end up with a file that's readily readable by Excel, rather than something that needs to be converted from HTML.

I know this isn't really an answer, but perhaps it can give you some ideas

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜