0

I have two function in one codeigniter controller which will set the payment status of user and send email. one main function will call send_mail. send_mail function will returns true or false. then in that main function, user will be redirected

here's the code..

function send_emai($id){  
 ..  
 ..  
 return $this->email->send(); 
}

function set_paid(){
 //set paid to user data
 $paid=$this->admin_model->set_paid($id_user);
 ..
 ..

 $sent=$this->send_email($id_user);

  if($paid && $sent){
     $this->session->set_flashdata('status',
   array(
     'color'=>'green',
     'message'=>'status paid<br/>Payment Confirmation Email sent'));
   }
  else{
     $this->session->set_flashdata('status',
   array(
     'color'=>'green',
     'message'=>'Booth status not paid<br/>Payment Confirmation Email not sent'));
  }
  redirect(admin/myclass/myfunction);
}

The errors i've got were

Cannot modify header information - headers already sent by (output started at C:\...\core\Exceptions.php:185)
Filename: libraries/Session.php

and this one.

Cannot modify header information - headers already sent by (output started at C:\...\core\Exceptions.php:185)
Filename: helpers/url_helper.php

I assumed this is because $this->send->email(). If I omitted that send function I could get redirected to the page and get notification set by session.
So, what can I do with this?

Mat
  • 202,337
  • 40
  • 393
  • 406
aTFa
  • 33
  • 1
  • 7
  • Do you have an error in your logs that will actually point to one of your files ? What if you put your send_mail function in a helper to remove it from the controller ? – Stéphane Bourzeix Feb 27 '12 at 07:56

2 Answers2

3

is error_reporting on at server? if so check for some notice or warning occurring. or try

error_reporting("E_ERROR");

the cannot modify header before any header redirect usually occur if there is something echoed or printed before it or even any HTML or plain text too.

hope this helps

Junaid
  • 2,084
  • 1
  • 20
  • 30
0

use $this->email->clear() after sending your mail. this initializes all the email variables to an empty state.

Code Prank
  • 4,209
  • 5
  • 31
  • 47