Send all WPMU emails via SMTP

I’ve tried plugins like “WP Mail SMTP” “WP SMTP” “Easy WP SMTP” “WP SMTP Config” noone is compatible with WPMU

Related posts

2 comments

  1. If I understand the question correctly, you’re having trouble with SMTP settings in a Multisite environment; specifically, your SMTP settings are not propagating throughout your sites from the root site.

    It’s possible that you need to configure the SMTP settings for every site individually, even if you’ve network activated the plugin. Some plugins aren’t written with WPMU / Multisite in mind.

    You might be able to programmatically set your SMTP settings, though.

    Note: The following code is untested and may or may not work for you. I also can’t speak as to its performance, though I don’t think there should be any significant issues.

    add_action( 'plugins_loaded', 'wpse101829_set_smtp' );
    function wpse101829_set_smtp() {
        $default_smtp = array(
            'host' => 'smtp.example.com',
            'port' => 25,
        );
        $option_name = '_smtp_settings';
        if ( is_multisite() ) {
            if ( ! get_site_option( $option_name ) ) {
                update_site_option( $option_name, $default_smtp );
            }
        } else {
            if ( ! get_option( $option_name ) ) {
                update_option( $option_name, $default_smtp );
            }
        }
    }
    

    Then, in your code sample above, you would use something like this:

    add_action( 'phpmailer_init', 'wpse8170_phpmailer_init' );
    function wpse8170_phpmailer_init( PHPMailer $phpmailer ) {
        // get the SMTP defaults
        if ( is_multisite() ) {
            $default_smtp = get_site_option( '_smtp_settings' );
        } else {
            $default_smtp = get_option( '_smtp_settings' );
        }
    
        $phpmailer->Host = $default_smtp['host'];
        $phpmailer->Port = $default_smtp['port']; // could be different
        $phpmailer->Username = 'my_username@example.com'; // if required
        $phpmailer->Password = 'mypassword'; // if required
        $phpmailer->SMTPAuth = true; // if required
        $phpmailer->SMTPSecure = 'ssl'; // enable if required, 'tls' is another possible value
    
        $phpmailer->IsSMTP();
    }
    

    References

    Codex pages for:

  2. WP Mail SMTP is compatible with multisite

    This is quite well hidden – you need to check the source code of the plugin and add some constants to your wp-config.php. If you configure WP Mail SMTP through the admin panel of each site, it will only work for those sites where it’s configured and will not work for network admin

    How to set up SMTP e-mail for wordpress multisite (WPMU)

    Check the code

    /**
     * Setting options in wp-config.php
     * 
     * Specifically aimed at WPMU users, you can set the options for this plugin as
     * constants in wp-config.php. This disables the plugin's admin page and may
     * improve performance very slightly. Copy the code below into wp-config.php.
     */
    define('WPMS_ON', true);
    define('WPMS_MAIL_FROM', 'From Email');
    define('WPMS_MAIL_FROM_NAME', 'From Name');
    define('WPMS_MAILER', 'smtp'); // Possible values 'smtp', 'mail', or 'sendmail'
    define('WPMS_SET_RETURN_PATH', 'false'); // Sets $phpmailer->Sender if true
    define('WPMS_SMTP_HOST', 'localhost'); // The SMTP mail host
    define('WPMS_SMTP_PORT', 25); // The SMTP server port number
    define('WPMS_SSL', ''); // Possible values '', 'ssl', 'tls' - note TLS is not STARTTLS
    define('WPMS_SMTP_AUTH', true); // True turns on SMTP authentication, false turns it off
    define('WPMS_SMTP_USER', 'username'); // SMTP authentication username, only used if WPMS_SMTP_AUTH is true
    define('WPMS_SMTP_PASS', 'password'); // SMTP authentication password, only used if WPMS_SMTP_AUTH is true
    

Comments are closed.