Welcome Guest, Not a member yet? Register   Sign In
Need Help with Sending HTML through send_mail()
#1

[eluser]vincej[/eluser]
HI - I have send_mail() working very well pulling various messages out of my DB. However I want to add css styling even pictures to those messages like so many ecommerce sites do. This is my problem. I have spent the day looking at forums . Nettuts, and the user guide to no avail.

My prefered choice is to store the various HTML / emebedded CSS 'templates'in MySQL.

Ok, Second option is to create HTML / CSS 'templates' in a seperate folder and store the address in the DB. However when I try that my templates come back blank ( maybe path problems ?? ) either way this seems to be a real challenge -

Addtionally I need to add $variables into some of the HTML 'templates' ie sale value etc.

I'm not even sure if
Code:
$this->email->initialize($config);
is even working properly, yet I think I have deployed it as per the user guide.

Here is my code - but it doesn't solve the problem and is pretty vanila send_mail()

does anyone know how ot do ths easily or a resource where it is explained ??

Many Many Thanks !

Controller - abreviated slightly for clarity:

Code:
function sendemail(){

$config['wrapchars'] = '76';
$config['mailtype'] = 'html';
//$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";

$this->email->initialize($config);

  
$this->load->helper('file');
  
if ($this->input->post('subject')){
    $test = $this->input->post('test');
     $template = $this->input->post('template');
  $newtemplate = $this->input->post('newtemplate');
   $subject = $this->input->post('subject');
   $msg = $this->input->post('message');
  $id = $this->input->post('id');
    
  if (!empty($template)) {
   $this->email->clear();
   $this->MEmail->SaveTemplate($id);
   $this->session->set_flashdata('message', 'Email Template Saved');
   redirect('admin/tools/sendemail','refresh');
    
   }

  if (!empty($newtemplate)) {
   $this->email->clear();
   $this->MEmail->CreateNewTemplate($id);
   $this->session->set_flashdata('message', 'New Template Saved');
   redirect('admin/tools/sendemail','refresh');
    
   }



   if ($test){
  
   $email_body = $this->load->view('test.php');
   //$file = base_url(). 'application/views/test.php';
   $this->email->clear();
   $this->email->from('abcd.com', 'abcd.com');
   $this->email->to('[email protected]');
   $this->email->subject($subject);
   $this->email->message($email_body);//$msg  
   $this->email->send();
   if (! write_file('../../tmp/email.log', $subject ."|||".$msg)){
   $this->session->set_flashdata('error','Unable to send Email');
   }
   else{
   $this->session->set_flashdata('message','Test Email Sent!');
   }
   redirect('admin/tools/sendemail','refresh');
        }
  
  
  }
#2

[eluser]InsiteFX[/eluser]
all images in email have to be inline images with the path pointing to your server were the images are.
For the css you will need to add it to the head section.
#3

[eluser]CroNiX[/eluser]
I've read that for html, inline css is better as a lot of mail readers will ignore the css file.
#4

[eluser]vincej[/eluser]
Thank you guys .. Cam I save them to MySql or must I save my HTML as seperate files ?

Also how do I get variables into the email ?

Many thanks !
#5

[eluser]CroNiX[/eluser]
You can create a view file and send the data to the view, like:
Code:
$data['name'] = 'CroNiX';
$html = $this->load->view('email_view', $data, TRUE);

This will render the contents of the view into the $html variable instead of immediately outputting it to the browser, which you can then use to send in the email.
#6

[eluser]vincej[/eluser]
CroxNox - Your'e brilliant ! Thank you - I wish I had your skills ! My guess is you're in Oz right ?
#7

[eluser]CroNiX[/eluser]
No, I've just been using CI a lot longer than you so I'm more familiar with it. There are many others here who understand it a lot better than I do, though Smile
#8

[eluser]vincej[/eluser]
Is that your'e real profile pic ? btw - I'm in Canada.
#9

[eluser]CroNiX[/eluser]
Yeah it's me. I held a green LED up to my face in the dark, took the pic and did the rest in photoshop. I'm down south in Portland, Oregon, USA. Nice to meet ya Smile
#10

[eluser]vincej[/eluser]
cool .. I need pic, We're neighbours - I'm in Calgary ! Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB