Sending SMTP email in Wordpress via server with self-signed certificate

Asked

Viewed 265 times

2

I have a Wordpress Multisite (4.3) on a server where sending emails is blocked. To send emails, an external server with authentication must be used.

By default, the native function wp_mail() Wordpress internally uses Phpmailer which in turn calls the mail() PHP. This procedure apparently does not use SMTP(?) and does not allow you to configure authentication or other options.

In the past, I had already used the plugin wp-mail-smtp to force the use of SMTP and fill in the authentication data.

However, the mail server uses a self-signed certificate and apparently from PHP 5.6 (which is the version used by WP) introduced certificate validation, causing the failure to send unless I use the following parameters:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

(source)

I can successfully send emails from a test script. But I don’t know how to force Wordpress to apply this setting. No plugin I found supports them, and the solution I found suggests editing the functions.php, which in my opinion would be a solution that would apply only to that theme on that particular site.

How to make something work for all sub-sites of Multisite?

1 answer

1

It is an interesting tool in single sites, but almost essential for Multisites:

Must Use Plugins « Wordpress Codex

All scripts you put inside the folder wp-content/mu-plugins will be run automatically without activation, well before the other plugins and generally on all websites of the network.

One can restrict its execution for this or that website.

As far as I’m concerned, that Eugene solution you found is the one that solves your problem, with special attention to reply from maestro Kaiser. Just create a PHP file with that code and put it inside /mu-plugins. If you put a plugin header, the listing gets more elegant in /wp-admin/network/plugins.php

As you apparently don’t know them, reference the various responses I wrote using the Must Use Plugins on WPSE and in the Soen.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.