Welcome Guest, Not a member yet? Register   Sign In
Sending data from a model into an email template
#1

[eluser]Unknown[/eluser]
Hi,

Im trying to retrieve data from one of my models and send that data to an email address.

I want to run the query, and post it to a html email. (or any plain text email to begin with)

I can get my Email Address form to send a html template to the address entered, but cannot draw data from the database to post into it.

My controller is:
Code:
function send_project()
    {    
        $this->load->library('form_validation');
        
        // field name, error message, validation rules
        $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
        
        if($this->form_validation->run() == FALSE)
        {
        $this->load->view('view_projects');
        }
        
        else{
        
        //it validated, so now needs to send an email
        
        
        
        $email = $this->input->post('email');
        
        
        if ($this->uri->segment(3)) {
            $id = $this->uri->segment(3);
        }
        $id = $this->uri->segment(3);
        $msg['query']= $this->site_model->view_project($id);
                
        $msg = $this->load->view('email_templates/email_tpl.php', '', true);
        
        
        $this->load->library('email');
        $this->email->set_newline("\r\n");
        
        $config['mailtype'] = 'html';
        $config['charset'] = 'UTF-8';
        $this->email->initialize($config);
        
        $this->email->from('[email protected]', 'Test Email with Data');
        $this->email->to($email);        
        $this->email->subject('Project Details');        
        $this->email->message($msg);
    
        
        if($this->email->send())
        {
            //echo 'Your email was sent.';    
    $data['main_content'] = 'thankyou_view';
    $this->load->view('includes/template_inner', $data);    
        }
        
        else
        {
            show_error($this->email->print_debugger());
        }
                
        }
    
    }


My model code:
Code:
function view_project($where){
        $sql = "SELECT * FROM projects, clients WHERE id = ? AND clients.clients_id = projects.clients_id";
        $query=$this->db->query($sql, array($where));
        return $query->result();
    }

I've spent quite a bit of time tweaking and trying to different ways to make this work, but struggling to see how to call that data so that it will appear in the email with no errors.

Any thoughts on how to fix it OR a better direction to go in would be much appreciated! I'm sure it must be possible, could really do with it working!

Many thanks!




Theme © iAndrew 2016 - Forum software by © MyBB