Welcome Guest, Not a member yet? Register   Sign In
Pass variables to page (like load->view('page',$data) for emailing the html contents?
#1

[eluser]x_dde_x[/eluser]
Not sure exactly how to ask this question, but basically I would like to render the contents of a page as a string, for the purpose of sending the page contents as an HTML email.

I've set this up before by writing a function to deliver the page as a string, but I'd like to keep HTML code out of any of my functions if possible.

So what I'm wondering, does Codeigniter have any capacity to do this for me? For instance:
Code:
$data['many_elements']="many elements to push to the controller";

  $this->load->library('email');
        $config['mailtype'] = 'html';
        $config['charset'] = 'iso-8859-1';
        $config['wordwrap'] = TRUE;
        $this->email->initialize($config);      
        
        $this->email->from('[email protected]', 'Name');
        $this->email->to('to@ example.com');

        $this->email->subject('subject');
        $message=$this->load->view('page_to_be_emailed',$data);
        $this->email->message($message);
#2

[eluser]Cro_Crx[/eluser]
You can output the contents of a view to a variable instead of the screen by adding a third parameter, by default it's false, but if you set to true will save to a variable. It's in the user guide, near the bottom:

http://ellislab.com/codeigniter/user-gui...views.html

So just chnage this line

Code:
$message=$this->load->view('page_to_be_emailed',$data);

With this:

Code:
$message=$this->load->view('page_to_be_emailed',$data, TRUE);

or just pass it directly to the email function like so:

Code:
$this->email->message(this->load->view('page_to_be_emailed',$data, TRUE));
#3

[eluser]NMTeck[/eluser]
That is a really good feature that I didn't know about. Glad to be in here to find all those little missing pieces to my CI experience.
#4

[eluser]x_dde_x[/eluser]
Ha! That's excellent. Thank you very much for the tip!




Theme © iAndrew 2016 - Forum software by © MyBB