?? GreyFile — Mystic File Browser

Current path: home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server/Admin/Controllers/



?? Go up: /home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server/Admin

?? Viewing: NotificationEmailDispatcher.php

<?php

namespace KS_PAC_DCFH\Admin\Controllers;

if (!defined('ABSPATH')) {
    exit;
}

class NotificationEmailDispatcher
{
    private static $_instance;

    public static function instance(): self
    {
        if (self::$_instance === null) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    public function entries_backup_notification(array $zip_file_details): void
    {
        ob_start();
        include dirname(__DIR__).'/template/notifications/backup-notification-email.php';
        $body = ob_get_clean();
        $email_handler = ks_pac_dcfh_app()->mail_handler();
        $to = ks_pac_dcfh_app()->settings_rep()->get_setting('entries_backup_email_address');
        $subject = __('Divi Contact Form Helper Entries Backup', 'divi-contact-form-helper');
        $email_handler->set_mail_content_type_html();
        $email_handler->set_mail_from($this->get_sender_email());
        $email_handler->set_mail_from_name('Divi Contact Form Helper');
        if (file_exists($zip_file_details['path'])) {
            $attachments = $zip_file_details['path'];
            $mail_sent = wp_mail($to, $subject, $body, [], [$attachments]);
            $status = [
                'sent' => $mail_sent,
                'datetime' => current_time('mysql'),
                'message' => $mail_sent
                    ? __('Email sent successfully with attachment.', 'divi-contact-form-helper')
                    : __('Failed to send email.', 'divi-contact-form-helper'),
            ];
            ks_pac_dcfh_app()->form_settings_manager()::update_backup_status($status);
            if ($attachments && file_exists($attachments)) {
                wp_delete_file($attachments);
            }
        }
    }

    public function entry_clone_notification(int $post_id, int $cloned_post_id): void
    {
        ob_start();
        include dirname(__DIR__).'/template/notifications/clone-notification-email.php';
        $body = ob_get_clean();
        $email_handler = ks_pac_dcfh_app()->mail_handler();
        $to = ks_pac_dcfh_app()->user_manager()::get_post_user_email($post_id);
        $subject = __('Entry Clones Notification', 'divi-contact-form-helper');
        $email_handler->set_mail_content_type_html();
        $email_handler->set_mail_from($this->get_sender_email());
        $email_handler->set_mail_from_name('Entry Clones Notification');
        wp_mail($to, $subject, $body);
    }

    private function get_sender_email(): string
    {
        $default_email = 'noreply@localhost.com';
        $remote_address = sanitize_text_field($_SERVER['REMOTE_ADDR'] ?? '');
        if (!in_array($remote_address, ['127.0.0.1', '::1'])) {
            $domain = wp_parse_url(get_bloginfo('url'), PHP_URL_HOST);

            return "noreply@$domain";
        }

        return $default_email;
    }
}


??

??