Storing email copy |
[eluser]minoflow[/eluser]
I'm building a site where I have a few functions in my controller that send out emails. One for example will send an email if someone forgets their password. The email will contain their password as well as information about their account pulled from the database. Everything works great, my only issue is that I don't like having all of the email's subject copy in my controller. Is there a way to take the copy and store it in a separate file? I've tried creating a config file, the problem was that the variables in the email subject were not being recognized and were throwing errors. It seems like a language file would make the most sense but I might run into the same problems with the variables. Any thoughts or ideas?
[eluser]Derek Jones[/eluser]
I'd use a language file. You'll be loading the language file and accessing the variables via $this->lang->line(), so you won't have any undefined variable issues.
[eluser]minoflow[/eluser]
Awesome, I'll give that a try. Thanks for the quick advise
[eluser]minoflow[/eluser]
So I made my language file and defined a lang line with the following text language/english/emails_lang.php Code: $lang['email_resetpassword'] = 'Hey '.$email_vars->name.', controllers/admin.php Code: $this->load->library('email'); I'm still getting errors that the variables within the lang line are undefined. The function is defining this within my controller. I was hoping that the language file could store the reference to the variables then my function could pick it up and define them. Looks like it can't?
[eluser]Derek Jones[/eluser]
That wouldn't work unless you defined $email_vars as a global object, which seems wasteful. Why not just use pseudo variables and let your controller replace it? Code: $lang['email_resetpassword'] = 'Hey {name}, And replace the {variables} with the actual data in the controller.
[eluser]minoflow[/eluser]
Rad, that worked... I used the code below to do a replace. Is this the best way to go about doing this? Is there a helper or something built into CI to do pseudo code replacements? Code: $subject = $this->lang->line('email_resetpassword'); Thanks for your help!
[eluser]Derek Jones[/eluser]
There's a Parser class that does something similar, but it's intended to operate on View files. So instead of a Language file solution, you'd have a view file for each email template. Code: $vars = array( |
Welcome Guest, Not a member yet? Register Sign In |