Welcome Guest, Not a member yet? Register   Sign In
How to use variables in email class?
#1

[eluser]Unknown[/eluser]
I a fairly new to codeigniter and php, and this may be an obvious question, but I need some help in using variables in the codeigniter email class.

I have a simple automated email response set up in a controller using this code:

$this->email->from('$my_email', '$my_name');
$this->email->to($contact_email);
$this->email->subject('Automate response');
$this->email->message('Thank you for your email, we will get back to you shortly');
$this->email->send();


My question is this: How do I use variables within the text of the "message" field? For example, I would like to be able to do something like:

$this->email->message('Dear $contact_name, Thank you for your email, we will get back to you shortly');

Like I said, I imagine that this is a fairly basic question, but I really appreciate any help you can give me!
#2

[eluser]cmgmyr[/eluser]
You can do this:
Code:
$this->email->message('Dear '.$contact_name.', Thank you for your email, we will get back to you shortly');

Or something like this:
Code:
$message = 'Dear '.$contact_name.', Thank you for your email, we will get back to you shortly';
$this->email->message($message);

It looks like you also have to change the first line to:
Code:
$this->email->from($my_email, $my_name);
(without the single quotes)
#3

[eluser]Unknown[/eluser]
Great, thanks for your help!




Theme © iAndrew 2016 - Forum software by © MyBB