Codeigniter $this->email->send() not working while mail() does
Use this setup email..
$this->load->library('email');$config['protocol'] = 'smtp';$config['smtp_host'] = 'ssl://smtp.gmail.com';$config['smtp_port'] = '465';$config['smtp_timeout'] = '7';$config['smtp_user'] = 'sender_mailid@gmail.com';$config['smtp_pass'] = 'password';$config['charset'] = 'utf-8';$config['newline'] = "\r\n";$config['mailtype'] = 'text'; // or html$config['validation'] = TRUE; // bool whether to validate email or not $this->email->initialize($config);$this->email->from('sender_mailid@gmail.com', 'sender_name');$this->email->to('recipient@gmail.com'); $this->email->subject('Email Test');$this->email->message('Testing the email class.'); $this->email->send();echo $this->email->print_debugger();
I faced this problem and found the following solution. Just a little change in the email config and it's working 100%:
$config['protocol'] = 'ssmtp';$config['smtp_host'] = 'ssl://ssmtp.gmail.com';
Codeigniter User Guide: https://www.codeigniter.com/user_guide/libraries/email.html
This setup works for me:
$config = Array( 'protocol' => 'smtp', 'smtp_host' => 'Your SMTP Server', 'smtp_port' => 25, 'smtp_user' => 'Your SMTP User', 'smtp_pass' => 'Your SMTP Pass', 'mailtype' => 'html' );$this->load->library('email', $config);$this->email->set_newline("\r\n");//Add file directory if you need to attach a file$this->email->attach($file_dir_name);$this->email->from('Sending Email', 'Sending Name');$this->email->to('Recieving Email address'); $this->email->subject('Email Subject');$this->email->message('Email Message'); if($this->email->send()){ //Success email Sent echo $this->email->print_debugger();}else{ //Email Failed To Send echo $this->email->print_debugger();}