Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft mail servers bounce back emails #261

Open
phobienbuon opened this issue Dec 2, 2024 · 0 comments
Open

Microsoft mail servers bounce back emails #261

phobienbuon opened this issue Dec 2, 2024 · 0 comments

Comments

@phobienbuon
Copy link

phobienbuon commented Dec 2, 2024

microsoft mail like ['@live.com','@msn.com','@outlook.com','@live.co.uk','@hotmail.com','@hotmail.co.uk'];
always return my email, so i block it from sending to those emails ending with @live.com','@msn.com','@outlook.com','@live.co.uk','@hotmail.com','@hotmail.co.uk'

I replace fluent-smtp.php

function fluentSmtpInit() {
    $application = new FluentMail\Includes\Core\Application;
    add_action('plugins_loaded', function () use ($application) {
        do_action('fluentMail_loaded', $application);
    });
}

fluentSmtpInit();

if (!function_exists('wp_mail')):
    function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) {
        return fluentMailSend($to, $subject, $message, $headers, $attachments);
    }
 else :
    if (!(defined('DOING_AJAX') && DOING_AJAX)):
        add_action('init', 'fluentMailFuncCouldNotBeLoadedRecheckPluginsLoad');
    endif;
endif;

With

function fluentSmtpInit() {
    $application = new FluentMail\Includes\Core\Application;
    add_action('plugins_loaded', function () use ($application) {
        do_action('fluentMail_loaded', $application);
    });
}

fluentSmtpInit();

if (!function_exists('wp_mail')) :
    function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) {
        // List of domains to block
        $blocked_domains = ['@live.com','@msn.com','@outlook.com','@live.co.uk','@hotmail.com','@hotmail.co.uk'];

        // Ensure $to is an array
        if (!is_array($to)) {
            $to = explode(',', $to);
        }

        // Filter recipients based on blocked domains
        $filtered_recipients = array_filter($to, function ($email) use ($blocked_domains) {
            foreach ($blocked_domains as $domain) {
                if (strpos($email, $domain) !== false) {
                    // Log blocked emails (optional)
                    error_log("Blocked email to $email");
                    return false; // Exclude this email
                }
            }
            return true; // Allow this email
        });

        // If no valid recipients remain, block the email
        if (empty($filtered_recipients)) {
            error_log("No valid recipients left after filtering. Email not sent.");
            return false; // Prevent email from being sent
        }

        // Update recipients
        $to = implode(',', $filtered_recipients);

        // Proceed with sending the email
        return fluentMailSend($to, $subject, $message, $headers, $attachments);
    }
else :
    if (!(defined('DOING_AJAX') && DOING_AJAX)) :
        add_action('init', 'fluentMailFuncCouldNotBeLoadedRecheckPluginsLoad');
    endif;
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant