View Issue Details

IDProjectCategoryView StatusLast Update
0008863phplist applicationHTML Email Supportpublic21-01-08 18:50
Reporterskoenig 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version2.11.2 
Target Version4.0.xFixed in Version2.11.3 
Summary0008863: New email header ordering breaks HTML rendering in most email clients
DescriptionChanges made to class.phpmailer.php and class.phplistmailer.php to support plugins break HTML rendering in mail clients because a double /r/n is introduced by phpmailer when it is finished so that the following headers appear after the main header content and after the double line break:

Content-Transfer-Encoding and Content-Type; charset

Additionally there is no double line break after these so that mail clients cannot distinguish between headers and content even if they get past the first double /r/n.

Thus the following is seen by mail clients:

--- SNIP ---
X-Priority: 3
X-Mailer: PHPMailer [version 1.73]
X-Mailer: phplist v2.11.2
X-MessageID: 296
X-ListMember: MYEMAIL
Precedence: bulk
MIME-Version: 1.0
X-OriginalArrivalTime: 05 Jan 2007 10:02:59.0327 (UTC) FILETIME=[ADE630F0:01C730B0]


Content-Transfer-Encoding: 8bit
Content-Type: text/html; charset="iso-8859-1"<html><div style="PADDING-RIGHT:10px;display:block;PADDING-LEFT:10px;
background:#c0cbd9;margin:auto;font:12px Verdana,Arial,Sans-serif;
color:#444">
<p style="font:10px/12px Verdana,Arial,Sans-Serif;">This email is sent to
visitors who have subscribed to one or more of the...

--- SNIP ---

What they should see:

--- SNIP ---
X-Priority: 3
X-Mailer: PHPMailer [version 1.73]
X-Mailer: phplist v2.10.3
X-MessageID: 304
X-ListMember: MYEMAIL
Precedence: bulk
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/html; charset="iso-8859-1"
X-OriginalArrivalTime: 03 Jan 2007 14:40:26.0856 (UTC) FILETIME=[1BC60680:01C72F45]

<html><div style="PADDING-RIGHT:10px;display:block;PADDING-LEFT:10px;
background:#c0cbd9;margin:auto;font:12px Verdana,Arial,Sans-serif;
color:#444">
<p style="font:10px/12px Verdana,Arial,Sans-Serif;">This email is sent to
visitors who have subscribed to one or more of the...

--- SNIP ---

The end result for recipients is that they see the raw code for the email as if it was text as above.

A temporary fix is to edit two files partially restoringthe original functionality:

1. in class.phpmailer.php starting at line 823 replace the Switch case statement with the following:

        switch($this->message_type)
        {
            case "plain":
# $this->ContentTypeHeader = $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
# $this->ContentTypeHeader .= sprintf("Content-Type: %s; charset=\"%s\"",
# $this->ContentType, $this->CharSet);
                $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
                $result .= sprintf("Content-Type: %s; charset=\"%s\"",
                                    $this->ContentType, $this->CharSet);
               break;
            case "attachments":
                // fall through
            case "alt_attachments":
                if($this->InlineImageExists())
                {
# $this->ContentTypeHeader = sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
# "multipart/related", $this->LE, $this->LE,
# $this->boundary[1], $this->LE);
                    $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
                                    "multipart/related", $this->LE, $this->LE,
                                    $this->boundary[1], $this->LE);
                }
                else
                {
# $this->ContentTypeHeader = $this->HeaderLine("Content-Type", "multipart/mixed;");
# $this->ContentTypeHeader .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
                    $result .= $this->HeaderLine("Content-Type", "multipart/mixed;");
                    $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
               }
                break;
            case "alt":
# $this->ContentTypeHeader = $this->HeaderLine("Content-Type", "multipart/alternative;");
# $this->ContentTypeHeader .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
                $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
                $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
                break;
        }

Notes:
(a) You will see below this statement the double /r/n added by phpmailer.
(b) Headers are now added into $result similar to the previous build - this will have a negative impact if you are trying plugins out as there is no longer a hook into which plugins can add their own headers. A more complete fix is to delay the insertion of the double /r/n until after the remaining headers are added by class.phplistmailer.php but I am not skillful enough to yet attempt this.

2. in class.phplistmailer.php line 97 comment out the plugin support for non plain text messages so that function CreateBody looks like this:

    function CreateBody() {
      $body = parent::CreateBody();
# if ($this->message_type != 'plain') {
# foreach ($GLOBALS['plugins'] as $plugin) {
# $plreturn = $plugin->mimeWrap($this->messageid,$body,$this->header,$this->ContentTypeHeader,$this->destinationemail);
# if (is_array($plreturn) && sizeof($plreturn) == 3) {
# $this->header = $plreturn[0];
# $body = $plreturn[1];
# $this->ContentTypeHeader = $plreturn[2];
# }
# }
# }
      return $body;
    }

Note:
(a) This will probably break plugin support entirely.

This temporary patch has only been tested with HTML emails.
TagsNo tags attached.

Relationships

related to 0002705 closed PHPList v2.11 release 

Activities

michiel

05-01-07 21:48

manager   ~0022274

ah, nice one.

I guess that's when using smtp though, and instead of commenting out all the changes, it's fairly quick to move the /r/n to the correct place instead.

michiel

05-01-07 21:51

manager   ~0022275

move the two lines

        if($this->Mailer != "mail")
            $result .= $this->LE.$this->LE;

from around line 851 and insert them after

        $this->header .= $this->ContentTypeHeader;

at around line 368

skoenig

05-01-07 22:18

reporter   ~0022277

Wow that was quick!

Yeah, see, you're just better. I'm using a sledgehammer and you're using a scalpel - hmm you found that in 3 seconds according to the posting log whereas my sledgehammer took me about a 2 hours just to find the bit of code that was dealing with headers lol..

Nice solution michiel.

michiel

05-01-07 22:30

manager   ~0022278

those are minutes, not seconds :-)

but yes, that's the advantage of having written, or at least hacked, most of the code. Your issue was important enough to warrant a quick check and get it resolved.

Harland Adelaars

08-01-07 16:53

reporter   ~0022303

If i move the lines

move the two lines

        if($this->Mailer != "mail")
            $result .= $this->LE.$this->LE;

to line 851 and insert them after

        $this->header .= $this->ContentTypeHeader;

My PHPList isn't sending messages anymore..

Please help...

If i don't change the file i get the following lines in every email:

Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="UTF-8"

Please help!

michiel

08-01-07 16:59

manager   ~0022304

ah, the penalty of speed.

the change also needs to change the variable of course:

instead of $result, use $this->header in the second line that you move.

Harland Adelaars

08-01-07 17:19

reporter   ~0022308

Okay, thanks for the quick reply, that works for sending messages from the admin console, but now i have the same problem as the release version that it's not sending confirm messages any more.

Before changing the phpmail code the confirm messages where send! But with the two lines:
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="UTF-8"

Now i don't receive them.....

The unsubscribe and update are sending messages!

Harland Adelaars

08-01-07 17:21

reporter   ~0022309

See also,

http://forums.phplist.com/viewtopic.php?t=7665&highlight=

Regards,
Harland

michiel

21-02-07 13:23

manager   ~0023941

fixed in cvs

skoenig

26-08-07 06:19

reporter   ~0031056

Hey Michiel,

Would you mind editing out or replacing my em address with em@email.com (or something like that) in the original post?

"X-ListMember: my_email_address"

As it's getting picked up by google and presumably bots...

~ Steph

michiel

26-08-07 12:36

manager   ~0031057

removed email from post