The fixed code should be like this
// If we are not given a Content-Type from the supplied headers, use
// text/html and *attempt* to strip tags and provide a text/plain
// version.
if (!isset($content_type)) {
// Try to figure out the content type with mime_content_type.
$tmppath = tempnam(sys_get_temp_dir(), ‘mg’);
$tmp = fopen($tmppath, ‘w+’);
fwrite($tmp, $message);
fclose($tmp);
// Get mime type with mime_content_type
$content_type = get_mime_content_type($tmppath, ‘text/plain’);
// Remove the tmpfile
unlink($tmppath);
}
// Allow external content type filter to function normally
if (has_filter(‘wp_mail_content_type’)) {
$content_type = apply_filters(
‘wp_mail_content_type’,
$content_type
);
}
And this fix will also fix issue: [Resolved] HTML rendered as plaintext in some emails