. * */ namespace Vvveb\Controller\Settings; use function Vvveb\__; use function Vvveb\config; use Vvveb\Controller\Base; use function Vvveb\email; use function Vvveb\setConfig; use Vvveb\System\Event; use Vvveb\System\Validator; class Email extends Base { function test() { $to = $this->request->post['to'] ?? false; if ($to) { $message = __('This is a test email to confirm that email is properly configured!'); try { $error = __('Error sending mail!'); if (email($to, __('Test email'), ['html'=> $message, 'txt' => $message])) { $this->view->success[] = sprintf(__('Email sent to %s!'), $to); } else { //$this->session->set('errors', $error); $this->view->errors[] = $error; } } catch (\Exception $e) { $error .= "\n" . $e->getMessage(); //$this->session->set('errors', $error); $this->view->errors[] = $error; } } return $this->index(); } function save() { $validator = new Validator(['settings']); $settings = $this->request->post['settings'] ?? false; $errors = []; if ($settings /*&& ($errors = $validator->validate($settings)) === true*/) { //$settings = $validator->filter($settings); //$results = \Vvveb\setMultiSetting('mail',$settings); $results = setConfig('mail',$settings); if ($results) { $this->view->success[] = __('Settings saved!'); } else { $this->view->errors[] = __('Error saving!'); } } else { $this->view->errors = $errors; } $this->index(); } function index() { $settings = config('mail', []); $drivers = ['mail' => 'Mail', 'smtp' => 'Smtp']; list($drivers) = Event::trigger(__CLASS__, __FUNCTION__, $drivers); $this->view->email = $settings; $this->view->drivers = $drivers; } }