'email'
];
}
public function get_site_template_name() : string {
return 'sending_test';
}
private function validate_result() : ?string {
if ($this->is_received('target') and !$this->is_validated('target')) {
return 'Target email is empty or not valid.';
}
return null;
}
private function prepare_mail() : single_mail {
$mail = new single_mail();
$mail->title = 'Test message from cx-newsletter.';
$mail->content = 'Hello!
This is tested message ';
$mail->content .= 'from cx-newsletter.
'; $mail->content .= 'If it is green, HTML work.
'; $mail->is_html = true; $mail->to = $this->get_validated('target'); return $mail; } public function process() : self { $validation = $this->validate_result(); if ($validation !== null) { $this->error_toast($validation); return $this; } if (!$this->is_received('target')) { return $this; } try { $mailer = new mail_manager($this->get_settings()); $mailer->prepare($this->prepare_mail()); if (!$mailer->send(true)) { throw new Exception('Can not send email.'); } } catch (Exception $exception) { $this->error_toast($exception->getMessage()); return $this; } $this->success_toast('Successed sended!'); return $this; } }