you can try my example
public function __construct()
{
parent::__construct();
$this->load->library('email');
$this->load->model('email_model');
}
public function emails()
{
$data['emails']=$this->email_model->get_records_of_chats_with_clients();
$this->load->view('templates/head', $data);
$this->load->view('templates/header', $data);
$this->load->view('email/view_emails', $data);
$this->load->view('templates/footer');
}
public function create()
{
$data['privileges'] = $this->email_model->get_privileges();
$this->form_validation->set_rules('privilege', 'privilege', 'required');
$this->form_validation->set_rules('from_name', 'from_name', 'required');
$this->form_validation->set_rules('from_email', 'from_email', 'required');
$this->form_validation->set_rules('to_email', 'to_email', 'required');
$this->form_validation->set_rules('title', 'title', 'required');
if($this->form_validation->run() === FALSE){
$this->load->view('templates/head', $data);
$this->load->view('templates/header', $data);
$this->load->view('email/create_email', $data);
$this->load->view('templates/footer');
} else {
$this->email_model->record_chats_with_clients();
redirect('email/emails');
}
}
public function kurti(){
$data['privileges'] = $this->email_model->get_privileges();
$email_to=$this->input->post('to_email');
$name_input=$this->input->post('name');
$name_session=$this->session->userdata('name');
$title=$this->input->post('title');
$message=$this->input->post('message');
if(!isset($name_input)){
$name=$name_session;
} else{
$name=$name_input;
}
$this->email->from('[email protected]', $name);
$this->email->to($email_to);
$this->email->subject($title);
$this->email->message($message);
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'example.serveriai.lt',
'smtp_port' => 587,
'smtp_user' => '[email protected]',
'smtp_pass' => 'example',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->email->set_mailtype("html");
$this->load->library('email', $config);
$this->form_validation->set_rules('to_email', 'Gavėjo adresas', 'required');
$this->form_validation->set_rules('title', 'Gavėjo žinutės tema', 'required');
$this->form_validation->set_rules('message', 'Žinutė', 'required');
if($this->form_validation->run() === FALSE){
$this->load->view('templates/head');
$this->load->view('templates/header');
$this->load->view('email/index', $data);
$this->load->view('templates/footer');
} elseif ($this->email->send()) {
$this->email_model->record_chats_with_clients($name);
$message = "success";
echo '
<script type="text/javascript">alert(\''.$message.'\');
window.location = \'/email/emails\';</script>';
}
else
{
if ($this->session->userdata('admin'=='1')){
show_error($this->email->print_debugger());
} else{
$message = "error!";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
}
'smtp_port' => 465? - Himanshu Upadhyay