Welcome Guest, Not a member yet? Register   Sign In
Export data from table and email it.
#1

[eluser]Brad K Morse[/eluser]
I am unsure about how to make this happen, I do have it working to export the table to a csv and it forces the download, but that won't be needed when trying to attach it to an email.

I also have a function for sending an email.

I need help putting these two together to export, then email that csv file.

Code:
// controller: export
function export() {
    $this->load->dbutil();
    $this->load->model('data_model');
    $csv = $this->data_model->exportCsv();
    $file_name = "spreadsheet.csv";
    force_download($file_name,$csv);
}

// model: exportCsv
function exportCsv() {
    $this->load->dbutil();
    $q = $this->db->select('first_name, tshirt')->order_by('first_name','asc')->get('data');
    return $this->dbutil->csv_from_result($q, ",", "\n");
}

// controller: emailCsv
function emailCsv() {
    $this->email->from('[email protected]', 'Jane Doe');
    $this->email->to('[email protected]', 'John Doe Morse');

    $this->email->subject('Spreadsheet');
    $this->email->message('Here is the list');    
    $this->email->attach($file); // want to attach the csv file here

    $this->email->send();

    echo $this->email->print_debugger();
}

The emailCsv controller function I just wrote, but not being used anywhere right now.

I am not sure how I can attach the csv file (spreadsheet.csv) to $this->email->attach() within emailCsv

Any help is very appreciated.


Messages In This Thread
Export data from table and email it. - by El Forum - 11-21-2010, 07:46 PM
Export data from table and email it. - by El Forum - 11-21-2010, 08:04 PM
Export data from table and email it. - by El Forum - 11-21-2010, 08:06 PM
Export data from table and email it. - by El Forum - 11-21-2010, 08:11 PM
Export data from table and email it. - by El Forum - 11-21-2010, 08:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB