Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachments not recognized since 6.7.0 in MS outlook/hotmail/gmail #2938

Open
2 of 3 tasks
lubosdz opened this issue Aug 5, 2023 · 10 comments
Open
2 of 3 tasks

Attachments not recognized since 6.7.0 in MS outlook/hotmail/gmail #2938

lubosdz opened this issue Aug 5, 2023 · 10 comments

Comments

@lubosdz
Copy link
Contributor

lubosdz commented Aug 5, 2023

  • Make sure you're using the latest version of PHPMailer
  • Check that your problem is not dealt with in the troubleshooting guide
  • Include sufficient code to reproduce your problem

Problem description

After upgrading to latest PHPMailer 6.8 emails stopped displaying file attachments. By downgrading traced back that issue started with 6.7.0 release. Last working was 6.6.5. Since 6.7.0 attachments will not be recognized in MS Outlook 2010 client and neither on hotmail.com & gmail.com (!).

I suspected that issue could have been related to newly added method stripTrailingBreaks() but cannot confirm - attachments still not recognized even if the method does not strip off trailing whitespaces.

Anyone experiencing same issue?

Here is commit comparison 6.6.5 - 6.7 - if you have any tip what's wrong pls drop it here, I will check out.

@lubosdz lubosdz changed the title Attachments not recognized since 6.7.0 in MS outlook client/hotmail/gmail Attachments not recognized since 6.7.0 in MS outlook/hotmail/gmail Aug 5, 2023
@Synchro
Copy link
Member

Synchro commented Aug 5, 2023

Can you show the SMTP transcript of sending a message that's failing in this way? Have you tried comparing messages created by the two different versions to see what the difference is?

@lubosdz
Copy link
Contributor Author

lubosdz commented Aug 6, 2023

Hi, I compared generated body and found the issue is caused by missing MIME preamble This is a multi-part message in MIME format. in this commit.

Showing attachments properly 6.6.5:

Content-Type: multipart/mixed;
 boundary="b1_OHfdma8GfBImaUYCc4p12Giwhoxlc43JKJMSmcca4Zw"
Content-Transfer-Encoding: 8bit
This is a multi-part message in MIME format.          <- note this line
                                                      <- note this line
--b1_OHfdma8GfBImaUYCc4p12Giwhoxlc43JKJMSmcca4Zw
Content-Type: multipart/alternative;
 boundary="b2_OHfdma8GfBImaUYCc4p12Giwhoxlc43JKJMSmcca4Zw"

--b2_OHfdma8GfBImaUYCc4p12Giwhoxlc43JKJMSmcca4Zw
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Attachment not shown 6.8.0:

Content-Type: multipart/mixed;
 boundary="b1=_BxnV55fkP55Ibm0jXjJItoipFfdZh1Snii1LO2saG5Y"
Content-Transfer-Encoding: 8bit
--b1=_BxnV55fkP55Ibm0jXjJItoipFfdZh1Snii1LO2saG5Y


Content-Type: multipart/alternative;
 boundary="b2=_BxnV55fkP55Ibm0jXjJItoipFfdZh1Snii1LO2saG5Y"

--b2=_BxnV55fkP55Ibm0jXjJItoipFfdZh1Snii1LO2saG5Y
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

After I manually added preamble attachments showed up properly.
It's weird that fixing one issue causes another one :-\

@Synchro
Copy link
Member

Synchro commented Aug 6, 2023

That is annoying. The preamble is entirely optional in the RFC - anything before the first MIME boundary should be ignored, and otherwise it breaks PHPMailer's DKIM, which is why it was removed. Are you sure those line breaks are exactly as in your message? There should be a blank line after the CTE header.

@lubosdz
Copy link
Contributor Author

lubosdz commented Aug 6, 2023

@Synchro
Yes & sorry. Here is screen with binary comparison.

I am using quite outdated client MS outlook 2010, not sure how it follows RFC. That could be excuse to ignore this thing. Unfortunately, I also noticed attachments not showing on gmail.com and hotmail.com - which should not be ignored. Perhaps you/somebody could double check & confirm that? Strange if nobody noticed that by now ..

@Synchro
Copy link
Member

Synchro commented Aug 6, 2023

That binary view is concerning - I suspect the reason it's working in the old one is not because of the preamble, but because of the position of the line break. Without a blank line before it, the preamble looks like a malformed header, and will probably be ignored, but the line after it will act as a acceptable separator between headers and body. In the 6.8 example, the break occurs after the boundary, meaning that the boundary will also be interpreted as a malformed header, but here it's more significant because it results in a broken MIME structure (i.e. the first boundary is effectively missing).

@zb3
Copy link

zb3 commented Aug 8, 2023

@Synchro , what break? Note the line count on the right.

What about setting $mimepre = static::$LE;?

@Synchro
Copy link
Member

Synchro commented Aug 8, 2023

There should be a blank line between lines 10 and 11 in both of them because the preamble (or lack of one) is part of the body, not the headers.

I need to look at the assembly of the message to see why the body isn't getting a break in the right place. Doing that with mimepre is a bit of a hack; I'd prefer to fix it properly!

@zb3
Copy link

zb3 commented Aug 8, 2023

I checked this and it turns out the line works for me without using this hack, also looking at SMTP code confirms that it should work properly. Gmail can recognize attachments.

@lubosdz, what transport were you using? Were you using SMTP?

@lubosdz
Copy link
Contributor Author

lubosdz commented Aug 8, 2023

@zb3 Thank you for checking .. I am not sure actually .. they were stored first as local EML files. This way I can check quickly proper content by opening in a local email client, e.g. MS Outlook. Once opened in Outlook, I would change the target email to gmail or hotmail address and send it (from outlook). Does that count as SMTP service .. ? Does it depend how Outlook connects to hosting mail server (POP3 / SMTP) .. ? Well, if it works for you and everybody, then it is probably OK, but I am not sure how to fix showing those attachments since my implementation has not changed since last 2 yrs and before PhpMailer 6.6.5 it worked OK.

@Synchro
Copy link
Member

Synchro commented Aug 8, 2023

It would help to see the code you're using to generate those messages.

If you set SMTPDebug = 2 and watch it sending the message, or grab a message with getSentMIMEMessage(), are the breaks in the right place?

I recommend using SMTP to localhost over the default mail() transport because it's both faster and safer, and also avoids some issues that are common with the mail function (strange wrapping, missing/duplicate headers, escaping problems).

The best way of keeping a copy of messages you send is to BCC yourself and have your mail server pipe the message back into your database. While it's fiddly to set up, the big upside of this approach is that you are guaranteed that the message is an exact copy of what was really sent, so things like DKIM signatures and message IDs (that might be generated by the server) will be present and correct, which may not be the case with local simulations like getSentMIMEMesage() provides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants