CodeIgniter Forums
Email Code Placement or Location - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Email Code Placement or Location (/thread-38647.html)



Email Code Placement or Location - El Forum - 02-14-2011

[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?


Email Code Placement or Location - El Forum - 02-14-2011

[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.


Email Code Placement or Location - El Forum - 02-14-2011

[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?


Email Code Placement or Location - El Forum - 02-14-2011

[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);



Email Code Placement or Location - El Forum - 02-14-2011

[eluser]cjke[/eluser]
Awesome thanks mate