• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Email Class: Send dynamic text from file?

#1
[eluser]kabbink[/eluser]
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:

Code:
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!
Kevin

#2
[eluser]freshface[/eluser]
Why not use a view?

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

#3
[eluser]kabbink[/eluser]
Great! That is exactly what I wanted I just wasnt sure I could do it that way. I am an MVC & OO noob!

Thanks!

#4
[eluser]sophistry[/eluser]
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.

#5
[eluser]Popcorn[/eluser]
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.

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

Kind Regards,
-Mathew


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.