| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace cx_newsletter;
- use \Exception;
- class sending_test_activity
- extends activity {
- public function show_after_button() : null {
- return null;
- }
- public function inside_buttons() : array {
- return [ 'test' ];
- }
- public function inside_inputs() : array {
- return [
- 'target' => '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!<br> This is tested message ';
- $mail->content .= 'from cx-newsletter. <p style="color: green;">';
- $mail->content .= 'If it is green, HTML work.</p>';
- $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;
- }
- }
|