I was also looking to send both plain text and html mail to get a better score on mail-tester.com
Hopefully I found this code snippet to add to you custom plugin, child-theme functions.php or even with the wp code snippet plugin:
/*
Description: Add plain text content to HTML email
Date: 6 January 2019
Author: WP Developer Guides
Author URL: wpdevguides.com
*/
class WPDG_Add_Plain_Text_Email {
function __construct() {
add_action( 'phpmailer_init', array( $this, 'add_plain_text_body' ) );
}
function add_plain_text_body( $phpmailer ) {
// don't run if sending plain text email already
// don't run if altbody is set
if( 'text/plain' === $phpmailer->ContentType || ! empty( $phpmailer->AltBody ) ) {
return;
}
$phpmailer->AltBody = wp_strip_all_tags( $phpmailer->Body );
}
}
new WPDG_Add_Plain_Text_Email();
This automatically associates a plain text version of your HTML email without modifying the common wp_mail
function.
eg:
wp_mail($to, $mail_subject, $body, $headers);
And now mail-tester.com is happy with my email contents.