Bug when sending multipart/mixed message "manually" #2134

@tsteur

Description

Hi there,

I noticed an issue with sending multipart/mixed message through a WordPress plugin. What's happening is that we actually configure PHPMailer to send a multipart/mixed message and send already the boundary in the header and content ourselves. I have a script to reproduce this issue here: https://gist.github.com/tsteur/6f23840e49cd7f8dc349d4c5bdfed33e

What's happening is that it works nicely in gmail and most other email clients, but Outlook in Office 365 shows this:

instead of this

The problem is that it adds here https://github.com/PHPMailer/PHPMailer/blob/v6.1.7/src/PHPMailer.php#L2493 an additional content type header which is confusing office 365 and overwriting the Content Type multipart/mixed header. This is what the header looks like

Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Content-Type: multipart/mixed; boundary="=_c3518fdad4b76fd9cadcb3e3cffc7698"
MIME-Version: 1.0
Content-Type: multipart/mixed; charset=UTF-8
--=_c3518fdad4b76fd9cadcb3e3cffc7698
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

This is what it should look like

Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Content-Type: multipart/mixed; boundary="=_c3518fdad4b76fd9cadcb3e3cffc7698"
MIME-Version: 1.0
--=_c3518fdad4b76fd9cadcb3e3cffc7698
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I suppose there are various ways to fix this issue. For example not adding that extra header if $this->ContentType === 'multipart/mixed'; or setting the correct message type (attach) if any of the custom headers already contain the multipart mixed header with a boundary here https://github.com/PHPMailer/PHPMailer/blob/v6.1.7/src/PHPMailer.php#L2907 so it would simply duplicate the Content-Type: multipart/mixed; boundary="=_c3518fdad4b76fd9cadcb3e3cffc7698" instead of using Content-Type: text/html; charset=utf-8.

Let me know if this helps you or if you need any more information. You should be able to reproduce the issue with the linked PHP script. I know we could use things like $phpMailer->addStringAttachment() but this is not as easily possible in WordPress and we can't use the regular way to add attachments in WordPress because we have the attachments as a string and not a file and for security reasons we would not want to create a file so it can be used using wp_mail().

Be great to make this use case work. Thanks