Welcome Guest, Not a member yet? Register   Sign In
Email Class: Send dynamic text from file?

Hello all!

This might be a fairly simple question but I've been working all day so maybe I've just lost it!

All I want to do is be able to send an email (preferably using the built in email library)
which is stored in a separate file but also has some dynamic variables in it.

Here is some pseudo code of what I am trying to do:

I would have a file called email.php containing something similar to:

Dear {$customer_name},

We appreciate your business!

Then send the email with something like:

$data['customer_name'] = 'Joe';
$this->email->message(email.php, $data);

Hope that made sense!
Thanks for all the help!

Why not use a view?

$data[’customer_name’] = ‘Joe’;
$content = $his->load->view("email/template1",$data);

Great! That is exactly what I wanted I just wasnt sure I could do it that way. I am an MVC & OO noob!


freshface's code example won't work ( not least because of one obvious typo using the variable $his instead of $this). you need to put TRUE as the third parameter to the this->load->view() call to get it to return the result as a string.

I use something similar in my authentication library to find "{key}" and then replace this with the real value.

The first parameter is the string you are looking for, the 2nd is what you are replacing it with and the 3rd is the message you are finding "{key}" in. You can assign this new message into your email script.

$message = str_replace('{key}', $key, $this->forgotten_password_message);

Kind Regards,

Theme © iAndrew 2016 - Forum software by © MyBB