PHPMailer / PHPMailer

The classic email sending library for PHP
GNU Lesser General Public License v2.1
20.77k stars 9.7k forks source link

6.2.0+ corrupts HTML body #3054

Closed duzenko closed 2 months ago

duzenko commented 2 months ago

Problem description

I'm trying to upgrade dependencies for a legacy project It's using PHPMailer v5 and all is good I tried to upgrade to the latest version but some HTML emails are now corrupted I narrowed it down to 6.2.0 which is the first version to exhibit this problem 6.1.8 was the last to send the HTML as is

Here's the diff between the email source as seen by the recipient server image

I tried to debug it in the source code and can confirm that the call to the mail() function in \PHPMailer\PHPMailer\PHPMailer::mailPassthru still has the right content. However somewhere along the way some HTML tags are lost. Since 6.1.8 still sends it correctly I can't help but this this has to be header/configuration issue.

I don't have any ideas but maybe someone has reported this issue before and you may advise in which direction to look.

Here's my initialization:

        $mailer = new PHPMailer\PHPMailer\PHPMailer( true );
        $mailer->CharSet = 'UTF-8';
        $mailer->IsHTML();
/// per-email data
        $mailer->Send();
duzenko commented 2 months ago

The only difference I can see is line breaks (/n in 6.1.8 vs. /r/n in 6.2.0)

duzenko commented 2 months ago

So. umm, why dropped support for legacy Linux senders? Should have at least mentioned it in the release notes image

duzenko commented 2 months ago

Fixed by adding

            $mailer->isSendmail();
Synchro commented 2 months ago

So. umm, why dropped support for legacy Linux senders? Should have at least mentioned it in the release notes

That didn't happen; nothing was dropped, and this change was explicitly mentioned in the release notes, to quote:

Resolve PHP 8 line break issues due to a very old PHP bug being fixed

PHP 8.0 fixed a bug relating to the use of line breaks in the mail transport, which meant that PHPMailer's workaround code was broken, and it caused double line breaks in PHP 8 versions running on Linux, which was fixed in that version. Anything running PHP older than PHP 8.0 (i.e. legacy code) would be unaffected, as you can see in the code.

duzenko commented 2 months ago

You are, in fact, wrong We have been running PHPMailer v5 with PHP 8.2 for one year, and it sent the same HTML in emails, as it had with PHP7 before But the change from v5 to v6 immediately broke the HTML