I know this question is partially concerns a third-party plugin, BackWPup, which is off-topic, but in general, in terms of WordPress and PHP: is it possible to hook into the wp_mail function so can I append text to the plugin's PHP generated email?
The email is sent by BackWPUp, a WordPress database backup plugin, and the email contains a success or fail message about the backup file. In my case, the email will go to a general email support address, and may be received by someone who may not fully familiar with how to deal with the email. I need to be able to add more instructional and explanatory text to the email, preferably at the beginning of the email.
And I need to add that text by using an external php function, because if I modify the plugin, the changes will be overwritten when the plugin is updated; so I need to add the function to either in the theme's functions.php file, or make my own simple WordPress plugin.
The wp_mail
function in the plugin that is used appears to be:
wp_mail(
$this->job['mailaddresslog'],
$subject,
file_get_contents( $this->logfile ),
$headers
);
is it possible to hook into the $message
and add additional text? It has been replaced with file_get_contents
in the function. Do I need to hook into file_get_contents
?
https://developer.wordpress.org/reference/functions/wp_mail/
Edit 7/28/19
I added a check for the subject line, as all emails sent had the additional text appended. Now, only BackWPUp emails get the additional text.
add_filter( 'wp_mail', 'wpse343761_filter_message' );
function wpse343761_filter_message( $atts ) {
if ( stripos( $atts['subject'], 'BackWPup')) {
if ( ! empty( $atts['message'] ) ) {
$atts['message'] .= 'Your additional text';
}
}
return $atts;
}
New questions on modifying message
: how can I use strip_tags
on the message
to convert the default html email to non-html email? Adding strip_tags($atts['message']);
before the return
doesn't do anything.
And, how can the "additional text message" be added to the beginning of the email? It's added to the end right now.