I tried the code below. At one time the code was working fine. I was able to send the emails. After a few minutes, when I tried it again without even changing anything, I get this error message Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
I dont know whats wrong. Lately I am facing a lot of similar bugs with codeigniter.
public function email($message = NULL, $subject=NULL, $email=NULL){
if(!isset($email)){
$to = $this->session->userdata('email');
}else{
$to = $email;
}
$this->load->library('email');
$this->email->from('noreply@mydomain.com', 'Mydomain');
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
}