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

[eluser]cjke[/eluser]
Hi,

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?
#2

[eluser]ramm[/eluser]
I do something like this:
Code:
$message = $this->parser->parse('mail_tpl', $data, TRUE);
$this->email->message($message);

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

[eluser]cjke[/eluser]
Nice - fast and simple, I like.

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

[eluser]ramm[/eluser]
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:
Code:
$message = $this->load->view('mail_tpl', TRUE); //TRUE is needed to turn the view into a string
$this->email->message($message);
#5

[eluser]cjke[/eluser]
Awesome thanks mate




Theme © iAndrew 2016 - Forum software by © MyBB