Bug Fix for Broken/Malformed Links in Header - Please implement this in future releases

Ages ago I posted about an issue that causes the unsubscribe, and other links embedded in the header to be malformed or broken:

Here is an example from an email send before the patch I am sharing:

Here is an example of the links after the patch:

image

These malformed links are critical now, as gmail and others use the one click unsubscribe for those who want to report spam, so having them function is very important.

I used ChatGPT to create this patch, and have tested it. It is attached and I hope I don’t have to keep patching it myself with new updates–please consider fixing this bug for good!

It is just small changes to two files:
/lists/admin/lib.php
/lists/admin/PHPMailer6/src/PHPMailer.php

link_header_patch.zip (62.2 KB)

1 Like

@keeenone This is a consequence of phplist sending using the php mail() function. In the config.php file

define("PHPMAILERHOST", '');

If you change to sending through an SMTP server then the encoding should not happen.See the online manual for guidance Installing phpList man... | phpList manual

Usually you can use the bounce email address $message_envelopeand its password for the settings.

I have always used SMTP to send, so this was happening in SMTP as well. Please include this fix in your new version if possible, thank you!

@keeenone Which version of phplist are you using? I send through SMTP and don’t have encoded headers. If I change to send using php mail() then I do get encoded headers.

I use the very latest version: v3.6.16

This problem has been going on continuously for years, but only now could I address it with a fix using ChatGPT for help. The subject is still doing this, but I haven’t had time to fix that yet.

I thought it might be easier if I also share just the changes made to those two files:

PHPLIST BUG FIX:
/lists/admin/lib.php
LINE 577

REPLACE THIS:

//$mail->addCustomHeader('List-Unsubscribe: <'.$removeurl.$sep.'email='.$to.'&jo=1>');
$mail->addCustomHeader('List-Unsubscribe', '<' . $removeurl . $sep . 'email=' . $to . '&jo=1>');

WITH THIS:
//RFC 2369/8058: keep List-* headers as raw angle-bracketed URLs (no RFC2047 encoding)
$mail->addCustomHeader(ā€˜List-Unsubscribe’, ā€˜<’.$removeurl.$sep.ā€˜email=’.$to.ā€˜&jo=1>’);

/lists/admin/PHPMailer6/src/PHPMailer.php
LINE 2668

REPLACE:

    //Add custom headers
    foreach ($this->CustomHeader as $header) {
        $result .= $this->headerLine(
            trim($header[0]),
            $this->encodeHeader(trim($header[1]))

WITH:

    //Do NOT RFC2047-encode RFC 2369/8058 List-* headers.
    //Some receivers (notably Microsoft) are strict about these remaining as
    //raw angle-bracketed URLs/mailto values.
    foreach ($this->CustomHeader as $header) {
        $hName  = trim($header[0]);
        $hValue = trim((string) $header[1]);

        if (preg_match('/^List-(?:Help|Unsubscribe|Unsubscribe-Post|Subscribe|Owner)$/i', $hName)) {
            $result .= $this->headerLine($hName, $this->secureHeader($hValue));
            continue;
        }

        $result .= $this->headerLine(
            $hName,
            $this->encodeHeader($hValue)