fix(email): set sender before PHPMailer init
This commit is contained in:
1 parent
0d7d4fea61
commit
05f40d7728
2 files changed
+24
-8
No files matched your search
@@ -17,8 +17,24 @@ add_filter('show_admin_bar', '__return_false');
|
||||
// SMTP 邮件配置注入
|
||||
// ============================================================
|
||||
|
||||
add_filter('wp_mail_from', function ($from) {
|
||||
if (!class_exists('\AKSRT\Settings\Settings')) return $from;
|
||||
$mail = \AKSRT\Settings\Settings::get_smtp();
|
||||
if (empty($mail['enabled'])) return $from;
|
||||
$configured = sanitize_email((string) ($mail['from_address'] ?? ''));
|
||||
return $configured !== '' ? $configured : $from;
|
||||
});
|
||||
|
||||
add_filter('wp_mail_from_name', function ($from_name) {
|
||||
if (!class_exists('\AKSRT\Settings\Settings')) return $from_name;
|
||||
$mail = \AKSRT\Settings\Settings::get_smtp();
|
||||
if (empty($mail['enabled'])) return $from_name;
|
||||
$configured = trim((string) ($mail['from_name'] ?? ''));
|
||||
return $configured !== '' ? $configured : $from_name;
|
||||
});
|
||||
|
||||
add_action('phpmailer_init', function ($phpmailer) {
|
||||
$mail = class_exists('\AKSRT\Settings\Settings')
|
||||
$mail = class_exists('\\AKSRT\\Settings\\Settings')
|
||||
? \AKSRT\Settings\Settings::get_smtp()
|
||||
: [];
|
||||
if (empty($mail['enabled']) || empty($mail['host'])) return;
|
||||
@@ -32,13 +48,6 @@ add_action('phpmailer_init', function ($phpmailer) {
|
||||
$phpmailer->SMTPSecure = (string) ($mail['encryption'] ?? 'ssl');
|
||||
$phpmailer->Timeout = 10;
|
||||
$phpmailer->Timelimit = 15;
|
||||
|
||||
$from_address = sanitize_email((string) ($mail['from_address'] ?? ''));
|
||||
if ($from_address !== '') {
|
||||
$from_name = (string) ($mail['from_name'] ?? get_bloginfo('name'));
|
||||
$phpmailer->setFrom($from_address, $from_name);
|
||||
}
|
||||
$phpmailer->FromName = (string) ($mail['from_name'] ?? get_bloginfo('name'));
|
||||
});
|
||||
|
||||
// mail_title_prefix is applied by the canonical renderer and by third-party wp_mail callers.
|
||||
|
||||
Reference in new issue
Block a user