CodeIgniter Forums
Sending html email and using static template - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Sending html email and using static template (/showthread.php?tid=61581)



Sending html email and using static template - kabeza - 04-27-2015

Hi guys

I'm sending html mail w/o any trouble, using email library
Now, I'm need to add some design to the "newsletter" system I'm building with CI

Which would be the best location to store images, css, etc. for the email template (relative?, absolute?) to be used within the email library, and how should I do to use and replace variables like {sender_name}, {sender_message} in the view (html template)

Thanks a lot in advance Cool


RE: Sending html email and using static template - CroNiX - 04-27-2015

I'd just create a view, and then use
PHP Code:
$data['image1'] = 'some_image.jpg';
$this->email->message($this->load->view('view_file'$dataTRUE)); //set the content of the email message to the rendered view 
to send dynamic data to the view and retrieve the rendered view file so you can output it in the email.


RE: Sending html email and using static template - Avenirer - 04-27-2015

Being an email, the paths should be absolute. For the second problem, look at the great documentation: http://www.codeigniter.com/user_guide/libraries/email.html


RE: Sending html email and using static template - kabeza - 04-28-2015

Thanks guys!
All went fine. I loaded views with third param TRUE, put absolute paths, and all went great.
I had trouble using TTL/SSL but solved by using smtp only, but I guess that's a problem from server


RE: Sending html email and using static template - madaan_tushar - 05-25-2015

$body contains the message and required the email-template.

Then you have to load the email library and the follwing to support HTML and send e-mail.
$this->email->set_mailtype("html");
$this->email->initialize($config);

$this->load->library('email');

$this->email->from('[email protected]', 'From Name');
$this->email->to('[email protected]');
$this->email->subject('Subject');
$this->email->message($body);
$this->email->send();

Smile