0

I am having an error Message: Undefined variable: posts. This is what I received after I sent an email using Codeigniter email.

I need to send an html output through CI email.

Controller:

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

    $config = array (
        'mailtype' => 'html',
        'wordwrap'=> TRUE,
        'charset'  => 'utf-8',
        'priority' => '1'
    );

    $this->email->initialize($config);
    $this->email->from('mywebsite.com', 'My website');
    $this->email->to('sender@gmail.com');
    $this->email->subject('Test');

    $data = $this->data['posts'] = $this->paypal->getRows();

    $message = $this->load->view('Receipt', '$data', true);

    $this->email->message($message);
    $this->email->send();   
}

View Receipt.php (this is the view I want to send in an email)

foreach ($posts as $row) {
    $row->room_type;
}
matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
user3631428
  • 131
  • 3
  • 14

1 Answers1

1

See how to pass data from controller to view

$data['posts'] = $this->paypal->getRows();

$message = $this->load->view('Receipt', $data, true);

No need '' in view when you assign array to view.

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37
  • It load in my current window. I don't need to load in my window/output. Just want to send in email with the output – user3631428 Sep 08 '18 at 09:29