I've tried plugins like "WP Mail SMTP" "WP SMTP" "Easy WP SMTP" "WP SMTP Config" noone is compatible with WPMU
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:
-
I have to edit The PHP mail() function
wp_mail($to, $subject, $message, $headers)
?? thanks for the help – Ghinnersmee Jun 4 '13 at 16:34 -
What my code does is set a default SMTP host & port in the options (or the site options if you're running Multisite), which you can then use in your
wpse8170_phpmailer_init()
function. According to thewp_mail()
Codex page, your SMTP information needs to be set in yourphp.ini
file. I don't know if you can programmatically override PHP's defaults if you're usingwp_mail()
. – Pat J Jun 4 '13 at 16:39 -
unfortunately doesn't work .thank you anyway .I have a vps and I think I can solve the problem with Ubuntu and sendmail module, I will contact my hoster to solve the problem . thanks for the help – Ghinnersmee Jun 4 '13 at 17:04
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)
/**
* 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
-
I have setup these things and it is the same. The mail is send with the deefoult settings, not these in
wp-config
. – gdfgdfg Jul 13 '19 at 21:57
wp_mail()
messages via SMTP? Also, is this a plugin that you're developing? – Pat J Jun 4 '13 at 14:25