Recommended location for email-related functions? |
[eluser]julietteculver[/eluser]
Hi everyone, First post here, so please be gentle :-) Our CI application has lots of functions for sending e-mails out for all sort of purposes, each of which has different text associated with it. So for instance there's one e-mail that gets sent out if somebody comments on something you have posted and another if somebody follows you on the site and so on. Currently I've got a single library with just these function iand the text for each hard-coded in the library, but that's obviously not ideal! It also feels messy having a library with a miscellany of different functions related to different features when the rest of the code is so neatly divided up by feature. Where would you recommend I put these functions and where should the text go? There seems to be a little bit of discussion on a similiar topic here http://ellislab.com/forums/viewthread/82035/ but I'm not convinced any of it quite addresses my situation. To make things more complicated, we've also done our own internationalisation for the site using GNU Gettext rather than CodeIgniter's language files, so I suspect any solution involving language files wouldn't easily work. Many thanks, Juliette
[eluser]mddd[/eluser]
I think emails are really a kind of views. In some of my projects, I have made a directory 'emails' inside the views folder. There I put the contents of the emails. You can even make a separate header/footer if you work with html-email, just like you would make a header/footer view for your site, and maintain them separately. Then, sending an email is as simple as setting the right email address, and setting the email message to the view contents. You can use variables in your emails just like in any other view. This wat you only need a few lines to send a mail. You can keep those lines in the controller or model where the email is 'activated'. Usually, the variables needed for building the email will already be known there. So no need to find out those variables again in a seperate 'email sending' piece of code.
[eluser]julietteculver[/eluser]
Thanks mddd - that's a useful way of looking at it. As you say, once I've taken that out into a view, putting the remaining code in the controller would be fine. Will give it a go!
[eluser]Cambo[/eluser]
I am keeping an email template in the DB and using the Template parser class to eval them. There is a good explanation here - http://www.webdevkungfu.com/email-templa...deigniter/
|
Welcome Guest, Not a member yet? Register Sign In |