awesomemotive / WP-Mail-SMTP

The most popular WordPress SMTP and PHP Mailer plugin. Trusted by over 3 million sites.
https://wordpress.org/plugins/wp-mail-smtp/
GNU General Public License v3.0
55 stars 34 forks source link

List-Unsubscribe header requires angle brackets, but all "html tags" are stripped #130

Closed tylercollier closed 7 months ago

tylercollier commented 8 months ago

I'm seeing this behavior in version WP Mail SMTP 3.0.3, 3.10.0, and 3.9.0. I'm using the Sendgrid provider.

Expected Behavior

There is a mail header called List-Unsubscribe. I learned about it due to Google/Yahoo's new requirements going into effect on February 1, 2024. The value requires it to be wrapped with angle brackets.

So, if I use a header like this:

List-Unsubscribe: <https://example.com/unsubscribe-id-123>

The value should not be removed.

Current Behavior

The value is being filtered/removed. It ends up blank, like this:

List-Unsubscribe: 

If I use multiple values (allowed), separated by commas, like this:

List-Unsubscribe: <mailto:unsubscribe-id-123@example.com>,<https://example.com/unsubscribe-id-123>

it ends up like this:

List-Unsubscribe: ,

Note the remaining comma. But everything between angle brackets has been removed.

Possible Solution

WP Mail SMTP uses WP::sanitize_value() in set_body_header(), which removes all tags with its call to wp_strip_all_tags(). It obviously doesn't do this for all headers, as my From and Reply-To headers use angle brackets and they're not filtered in this way. But I tried another custom header, which I called X-Proof, and it exhibited the same behavior as List-Unsubscribe. So a possible solution is to relax the filter for this single special header.

Steps to Reproduce

  1. Use Sendgrid. I'm guessing all API providers have the same issue? I use Mailtrap via SMTP in dev and it did not have this issue.
  2. Add a List-Unsubscribe header with a value containing angle brackets.
capuderg commented 8 months ago

Thank you @tylercollier for the detailed explanation. We'll look into it and resolve it in one of the future releases.

tylercollier commented 8 months ago

@capuderg Great! May I ask for an ETA? The page I linked says that Google's deadline for bulk senders is February 1, 2024.

Requirements for sending 5,000 or more messages per day

Starting February 1, 2024, senders who send more than 5,000 messages per day to Gmail accounts must meet the requirements in this section. ... Marketing messages and subscribed messages must support one-click unsubscribe, and include a clearly visible unsubscribe link in the message body.

I'm hoping the change can happen ASAP so that I have time to deploy it and test. Thanks for the consideration!

capuderg commented 7 months ago

Hi @tylercollier we plan to make a small lite release in the next few days.

tylercollier commented 7 months ago

Well that will teach me not to subscribe to version updates. I see a new version was cut the day of your last comment. I'll check it out tomorrow. Thanks!