我相信你需要的是phpmailer_init
行动挂钩。
这是你可以做的一件事。
add_action( \'phpmailer_init\', \'custom_smtp_settings\' );
function custom_smtp_settings( $phpmailer ) {
$phpmailer->isSMTP();
switch ($_SERVER[\'HTTP_HOST\']) {
case \'example1.com\': //name only, no http
$phpmailer->Host = \'smtp.example1.com\';
$phpmailer->SMTPAuth = true; // Force it to use Username and Password to authenticate
$phpmailer->Port = 25;
$phpmailer->Username = \'example1\';
$phpmailer->Password = \'example1pass\';
// Additional settings…
$phpmailer->SMTPSecure = "tls"; // Choose SSL or TLS, if necessary for your server
$phpmailer->From = "[email protected]";
$phpmailer->FromName = "Example One";
break;
case \'example2.com\':
$phpmailer->Host = \'smtp.example2.com\';
$phpmailer->SMTPAuth = true; // Force it to use Username and Password to authenticate
$phpmailer->Port = 25;
$phpmailer->Username = \'example2\';
$phpmailer->Password = \'example2pass\';
// Additional settings…
$phpmailer->SMTPSecure = "tls"; // Choose SSL or TLS, if necessary for your server
$phpmailer->From = "[email protected]";
$phpmailer->FromName = "Example Two";
break;
}
}