Add the line of codes in your wp-config.php just before /* That's all, stop editing! Happy blogging. */
$servers = [
[
'host' => 'smtp.example1.com', // Address of the SMTP server.
'port' => '587', // Port of the SMTP server. Options may be '25', '465', '587' or '2525'.
'secure' => 'tls', // encryption to use on the SMTP connection. Valid options are '', 'ssl' or 'tls'.
'authentication_required' => 'true', // set this to 'false' if your SMTP server does not require authentication
// If 'authentication_required' above is set to 'true', the following credentials will be required
'name' => 'Your Name', // SMTP From name
'username' => '[email protected]', // Username to use for SMTP authentication
'password' => 'password', // Password to use for SMTP authentication
],
[
'host' => 'smtp.example2.com', // Address of the SMTP server.
'port' => '465', // Port of the SMTP server. Options may be '25', '465', '587' or '2525'.
'secure' => 'ssl', // encryption to use on the SMTP connection. Valid options are '', 'ssl' or 'tls'.
'authentication_required' => 'true', // set this to 'false' if your SMTP server does not require authentication
// If 'authentication_required' above is set to 'true', the following credentials will be required
'name' => 'Your Name', // SMTP From name
'username' => '[email protected]', // Username to use for SMTP authentication
'password' => 'password', // Password to use for SMTP authentication
],
[
'host' => 'smtp.example3.com', // Address of the SMTP server.
'port' => '2525', // Port of the SMTP server. Options may be '25', '465', '587' or '2525'.
'secure' => '', // encryption to use on the SMTP connection. Valid options are '', 'ssl' or 'tls'.
'authentication_required' => 'true', // set this to 'false' if your SMTP server does not require authentication
// If 'authentication_required' above is set to 'true', the following credentials will be required
'name' => 'Your Name', // SMTP From name
'username' => '[email protected]', // Username to use for SMTP authentication
'password' => 'password', // Password to use for SMTP authentication
],
];
$server = $servers[array_rand($servers)]; //Picks a random server (or however you want to select a server)
define( 'SMTP_FROM', '[email protected]' );
define( 'SMTP_TO', '[email protected],[email protected],[email protected]' ); // SMTP From email address. This can be static.
define( 'SMTP_USER', $server['username']); // Username to use for SMTP authentication
define( 'SMTP_PASS', $server['password']); // Password to use for SMTP authentication
define( 'SMTP_HOST', $server['host']); // The hostname of the mail server
define( 'SMTP_NAME', $server['name']); // SMTP From name
define( 'SMTP_PORT', $server['port']); // SMTP port number
define( 'SMTP_SECURE', $server['secure']); // Encryption system
define( 'SMTP_AUTH', $server['authentication_required']); // Use SMTP authentication
Save the file and upload it to the server.
Now you can add any number of SMTP servers to send mail.