Welcome Guest, Not a member yet? Register   Sign In
Keeping email DRY
#1

[eluser]Dan Bowling[/eluser]
I've got an app that sends emails in lots of places, so I'd like to keep as much of it centralized as possible.

I already have an Email Controller and I'd like to have the following code in it:
Code:
function send_as_logged_in_user($to, $subject, $message) //sends an email as the logged-in user's credentials
    {
        $this->load->library('email');
        
        $this->email->from($this->session->userdata('user_email'), $this->session->userdata('user_name'));
        $this->email->to($to);
        $this->email->bcc($this->session->userdata('user_email'));
        
        $this->email->subject($subject);
        $this->email->message($message);    
        
        $this->email->send();
    }

I'd love to be able to send an email with a single line call to it (from any controller in my app), but passing info via the URL could be messy. I may also have to do a loop through lots of records to send an email to each record with the users credentials, so simply setting flash data doesn't feel like a good fit.

Is Wick the only solution to this problem?




Theme © iAndrew 2016 - Forum software by © MyBB