Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 48
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Emailing An Excel File

    hi all... ok i have set up a pretty neat php page which basically emails me what members have logged in over the past month... using a cron job i run this script every month, and get emailed results for the previous month... NOW the tricky part in this email i also want to have an excel file attached with that data... i can make the excel page separately but aren't sure how to get it all happening together... anyone know if it can be done?

    not sure how possible it...

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Where is the Excel file located, on your local PC, or in a website directory?

    If you can upload the Excel file with a defined name that is either always
    the same name, or a defined name that is part of the month/year....

    example: excelfile.xls
    or: excel0707.xls , excel0807.xls (month year .xls)

    The PHP script could find and attach the file automatically if it knows
    where to look and the name of the file.

    You would just have to make sure that the file is there when it
    does its email thing.

    You'll find many examples of sending file attachments with PHP using Google.

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ahhhhhh ok got it, so then I would have to create the Excel file and save it somehow to the server... Is that possible?

    Or can I actually make it all happen using the same php page?
    Last edited by tomyknoker; 07-16-2007 at 01:24 PM.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Yes, with a simple PHP upload script, you could upload your Excel
    file into a particular directory. That could be done on a webpage that
    only you know the URL (no big security issues to deal with). A simple
    form for uploading a file.

    Your CRON job script would look for that file at any time.

    You can't have a script upload a file from your PC automatically,
    it requires your intervention.

    EDIT:
    It is possible to have an .exe program running on your PC that uploads
    an Excel file automatically, from your PC to your website.... but that program
    would need to be written (custom using C++, Visual Basic, or an Excel Macro?)
    It's something you would need to do on your PC and have it running.
    That's a bit beyond the scope of this forum.


    .
    Last edited by mlseim; 07-16-2007 at 01:30 PM.

  • #5
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ok sounds good well I've been using a PEAR class to write and format the Excel file... At the top of this pgae I have the following code...

    PHP Code:
    $xls->send("test.xls"); 
    This basically names the file to be sent, do you know what I would need to change to upload?

  • #6
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    If you're not using any fancy excel features, its probably easier to send a csv - its plain text and can be read by any spreadsheet or text package. Plus php has built in functions for reading and writing csvs http://www.php.net/manual/en/function.fputcsv.php

    ofcourse you dont need to save the file anywhere to send it as an attachment - you just need to know what would be in the file.

    So you would want a script that runs your queries. Writes what would be in the file to a variable then sends the email.

    Sitepoint has a good article about advanced email features - including how to send attachments http://www.sitepoint.com/print/advanced-email-php

  • #7
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Yea that's my drama, I'm using the PEAR Spreadsheet Class, so pretty code heavy but the php page with generates the Excel works flawlessy and my php code which emails me a report just in the email works flawlessy it's combining the two that I am really struggling with...

  • #8
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    at what point are you struggling? Did you read the sitepoint article?

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    So, if I got this right ... the only thing you need to do is
    upload the file from your PC to your website using PHP?

    The part about emailing it is working OK?

  • #10
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    As I interpret it he has 2 scripts, one that sends an email and another that generates an excel file and he needs to merge the 2 together - so that the excel file goes with the email.
    Could be wrong though but I dont see any mention (from him at least) of the excel file being on his PC - or any other machine that isnt the server that is sending the email.

  • #11
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by NancyJ View Post
    As I interpret it he has 2 scripts, one that sends an email and another that generates an excel file and he needs to merge the 2 together - so that the excel file goes with the email.
    Could be wrong though but I dont see any mention (from him at least) of the excel file being on his PC - or any other machine that isnt the server that is sending the email.
    Hi Nancy, yes that's correct so what I still don't know is can it be done? Or do I need to run the upload script first and then run the email script second which would attach the file that I guess would have to sit in a directory on my server?

  • #12
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    ofcourse it can be done. Have you tried anything yet? Did you read the article on sending attachments?
    If the excel file is on the server why do you need an upload script?
    If you can create the file and you can send emails with attachments, where is the problem?

  • #13
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Searching Google, there are tons of tutorials and code snippets on
    emailing a file attachment from your server. I would start there, and
    it would be faster than communicating back and forth with these posts.

  • #14
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by NancyJ View Post
    ofcourse it can be done. Have you tried anything yet? Did you read the article on sending attachments?
    If the excel file is on the server why do you need an upload script?
    If you can create the file and you can send emails with attachments, where is the problem?
    hi nancy, no at the moment i have a page which produces an excel file, it simply 'downloads' it to my desktop... what i need to change on the page though is instead of downloading the page, i want the page to upload to the server... i have done a search and am having no luck at all...

  • #15
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    no you dont. The file is being created on your server. You need to modify your code to either save the file to a location where a separate script can read it in to the email or save the content to a variable that you can send in the email.


  •  
    Page 1 of 4 123 ... LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •