Looking at the source of the wp_mail()
function, there’s a filter right near the top:
$atts = apply_filters(
'wp_mail',
compact( 'to', 'subject', 'message', 'headers', 'attachments' )
);
// Expanded for clarity.
(Aside:
compact()
is a PHP function that creates an array from a set of arguments. In this case, it’s making an array of the$to
,$subject
,$message
,$headers
, and$attachments
parameters passed towp_mail()
.)
…and then a little further on:
if ( isset( $atts['subject'] ) ) {
$subject = $atts['subject'];
}
So yes, you can filter the message. Something like this should do the trick:
add_filter( 'wp_mail', 'wpse343761_filter_message' );
function wpse343761_filter_message( $atts ) {
if ( ! empty( $atts['message'] ) ) {
// If there's already a message, add to it.
$atts['message'] .= 'Your additional text';
} else {
// If there's not a message set yet, set one.
$atts['message'] = 'Your desired message';
}
return $atts;
}
Note: This code is untested.
Edit: In response to your update And, how can the “additional text message” be added to the beginning of the email?:
Change this line:
$atts['message'] .= 'Your additional text';
to:
$atts['message'] = 'Your additional text' . $atts['message'];
And to your strip_tags()
usage question, you can do this:
$atts['message'] = strip_tags( $atts['message'] );
on the line before you return
. (You can’t just use strip_tags( $atts['message'] )
because that doesn’t assign the stripped string to anything.)