From 3ef158b6381d41463a61ee0b222861f4bd64ec90 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Tue, 21 Nov 2023 12:12:53 +0100 Subject: [PATCH] function sendTestmail --- application/controllers/Options.php | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/application/controllers/Options.php b/application/controllers/Options.php index f22eee3e..778756de 100644 --- a/application/controllers/Options.php +++ b/application/controllers/Options.php @@ -380,4 +380,47 @@ class Options extends CI_Controller { redirect('/options/oqrs'); } + public function sendTestMail() { + $this->load->model('user_model'); + + $id = $this->session->userdata('user_id'); + + $email = $this->user_model->get_user_email_by_id($id); + + if($email != "") { + + $this->load->library('email'); + + if($this->optionslib->get_option('emailProtocol') == "smtp") { + $config = Array( + 'protocol' => $this->optionslib->get_option('emailProtocol'), + 'smtp_crypto' => $this->optionslib->get_option('smtpEncryption'), + 'smtp_host' => $this->optionslib->get_option('smtpHost'), + 'smtp_port' => $this->optionslib->get_option('smtpPort'), + 'smtp_user' => $this->optionslib->get_option('smtpUsername'), + 'smtp_pass' => $this->optionslib->get_option('smtpPassword'), + 'crlf' => "\r\n", + 'newline' => "\r\n" + ); + + $this->email->initialize($config); + } + + $message = $this->load->view('email/testmail.php', NULL, TRUE); + + $this->email->from($this->optionslib->get_option('emailAddress'), $this->optionslib->get_option('emailSenderName')); + $this->email->to($email); + $this->email->subject('Cloudlog Test-Mail'); + $this->email->message($message); + + if (! $this->email->send()){ + $this->session->set_flashdata('success', 'Email settings are incorrect.'); + } else { + $this->session->set_flashdata('message', 'Email settings seem to be correct'); + } + } else { + $this->session->set_flashdata('error', 'You have no email address in your account settings!'); + } + } + }