Welcome Guest, Not a member yet? Register   Sign In
Email Code Placement or Location


Just writing up the code for the part of the site that will automatically shoot off an email to the user. It will be a html email (with a fallback text version) and is quite lengthy.

A controller is organizing the data for the email (database data, like user name, etc) but the content of the email is quite large and doesn't seem right to put it in the controller itself, it seems more like a view.

Should the content of the email be in the controller or the view? or something else?

I do something like this:
$message = $this->parser->parse('mail_tpl', $data, TRUE);

Works like a charm, you can use the parser library to pass some variables to the template.

Nice - fast and simple, I like.

Can 'mail_tpl' be just a html file mail_tpl.html that sits in the views folder?

It needs to be php mail_tpl.php (or you would have to specify the extension).

If you don't need any variables on it, you don't need the parser, or $data:
$message = $this->load->view('mail_tpl', TRUE); //TRUE is needed to turn the view into a string

Awesome thanks mate

Theme © iAndrew 2016 - Forum software by © MyBB