这可以通过过滤wp_mail
函数,检查是否to
设置为管理电子邮件,如果是,请添加其他电子邮件地址,并将参数返回到wp_mail
add_filter( \'wp_mail\', \'my_custom_to_admin_emails\' );
/**
* Filter WP_Mail Function to Add Multiple Admin Emails
*
*
*
* @param array $args A compacted array of wp_mail() arguments, including the "to" email,
* subject, message, headers, and attachments values.
*
* @return array
*/
function my_custom_to_admin_emails( $args ) {
// If to isn\'t set (who knows why it wouldn\'t) return args
if( ! isset($args[\'to\']) || empty($args[\'to\']) ) return $args;
// If TO is an array of emails, means it\'s probably not an admin email
if( is_array( $args[\'to\'] ) ) return $args;
$admin_email = get_option( \'admin_email\' );
// Check if admin email found in string, as TO could be formatted like \'Administrator <admin@domain.com>\',
// and if we specifically check if it\'s just the email, we may miss some admin emails.
if( strpos( $args[\'to\'], $admin_email ) !== FALSE ){
// Set the TO array key equal to the existing admin email, plus any additional emails
//
// All email addresses supplied to wp_mail() as the $to parameter must comply with RFC 2822. Some valid examples:
// user@example.com
// User <user@example.com>
$args[\'to\'] = array( $args[\'to\'], \'another@domain.com\', \'Admin4 <admin4@domain.com>\' );
}
return $args;
}
我们将TO作为数组返回,如下所示
wp_mail
将处理阵列并根据需要将其分解以发送电子邮件