Вы можете попробовать следующий скрипт:
$this->load->library("email");
$config = array("protocol"=>"smtp","smtp_host"=>"ssl://smtp.gmail.com","smtp_user"=>"$smtp_user","smtp_pass"=>"$smtp_password","smtp_port"=>"465","mailtype"=>"html","charset"=>"utf-8","newline"=>"\r\n");
$this->email->initialize($config);
$this->email->from("$email", "$name");
$this->email->to($to_email);
$this->email->subject("$subject");
$this->email->message("$message");
//Send mail
if($this->email->send()){
echo "SUCCESS";
}
else{
echo "FAILED";
}