I believe the answer in your particular case does not involve the bug that is mentioned in the linked thread. There is no need to set custom headers to achieve what you state you want to do.
Instead you simply set the alternative body as text using $phpmailer->AltBody
. This automatically sets the to content type multipart/alternative
(not multipart/mixed) and you allow the phpmailer
class to take care of the rest without needing to set custom headers manually.
add_action('phpmailer_init','wp_mail_set_text_body');
function wp_mail_set_text_body($phpmailer) {
$phpmailer->AltBody = strip_tags($phpmailer->Body);
}
$to = '[email protected]';
$headers = array();
$attachments = array(dirname(__FILE__).'/test.txt');
wp_mail($to,$subject,$message,$headers,$attachments);
If you add attachments, the overall content type will automatically become multipart/mixed
with multipart/alternative
inside of that wchi contains text/plain
and text/html
parts, then followed by the attachments.
You can also add multipart/related
(inline) attachments such as images by passing them to wp_mail
via $attachements
(with the 5th parameter as 'inline') - or even declaring them within the HTML body itself. These will not be accessible to the text version as far as I know.
text/html
via the provided filter? developer.wordpress.org/reference/hooks/wp_mail_content_typewp_mail()
in my question: wordpress.stackexchange.com/questions/191923/… -- Best of luck!