Email the excel file to myself

Sarbloh 10 Feb, 2011
Hi Guys!

How can I email the excel file to myself after everytime someone registers? I searched the forum and saw a few threads of opening the excel file after a user registers for the user, but nothing that shows how to have the excel file emailed to the adminstrator?

Please help!
GreyHead 10 Feb, 2011
Hi Sarbloh,

What Excel file??

Bob
Sarbloh 10 Feb, 2011
Hey Bob,

The excel file that you can export from the backend, which stores all the data from the table.
GreyHead 11 Feb, 2011
Hi Sarbloh,

Interesting, I don't recall anyone asking that before.

It could be done if you add the code to create the Excel file in the OnSubmit Before Email box and then attach the file to the email.

Bob
Sarbloh 11 Feb, 2011
Hi Bob,

Thank you!

I found this code:
<?php
    global $mainframe;
       $database =& JFactory::getDBO();

      
       
       $tablename = 'jos_chronoforms_BLXRegistration';
       $tables = array( $tablename );
       $result = $database->getTableFields( $tables );
       $table_fields = array_keys($result[$tablename]);
       
       $database->setQuery( "SELECT * FROM ".$tablename."");
       $datarows = $database->loadObjectList();
       
       $titcol = 0;
       foreach($table_fields as $table_field){
          if($titcol){$csvline .=",";}
          $csvline .= $table_field;
          $titcol++;
       }
       $csvline .="\n";


             
       $datacol = 0;
       $rowcount = 1;
       foreach($datarows as $datarow){
          foreach($table_fields as $table_field){
             if($datacol){$csvline .=",";}
             $csvline .= '"'.addslashes($datarow->$table_field).'"';
             $datacol++;
          }
          $csvline .="\n";
          $datacol = 0;
          $rowcount++;
       }
       
       if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
          $UserBrowser = "Opera";
       }
       elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
          $UserBrowser = "IE";
       } else {
          $UserBrowser = '';
       }
       $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
       @ob_end_clean();
       ob_start();

       header('Content-Type: ' . $mime_type);
       header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');

       if ($UserBrowser == 'IE') {
          header('Content-Disposition: inline; filename="' . "ChronoForms - ".$tablename." - ".date("j_n_Y").'.csv"');
          header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
          header('Pragma: public');
       }
       else {
          header('Content-Disposition: attachment; filename="' . "ChronoForms - ".$tablename." - ".date("j_n_Y").'.csv"');
          header('Pragma: no-cache');
       }
       print $csvline;
       exit();
    ?>




It works, and when someone submits the form it prompts them do download the file, how can I change this code so that it emails the file to me instead? Appreciate all your help!!
GreyHead 11 Feb, 2011
Hi Sarbloh,

Instead of using the ob_ methods and print I'd use the PHP file methods to write the output to a file, you can then add this to the form attachments array.

Bob
This topic is locked and no more replies can be posted.