Handling of List-Unsubscribe callbacks on server

1.4k views Asked by At

When adding 'List-Unsubscribe' email headers, what kind of handling is required on the server-side for the callbacks?

It's possible to add both a mailto-link and a web-link to the header, in PHPMailer it could look like this:

$email->AddCustomHeader("List-Unsubscribe: <mailto:[email protected]?subject=Unsubscribe>, <http://example.com/unsubscribe.php?unsubscribeid=$id>");

But does the mailto-address have to somehow automatically handle the unsubscription, or is it okay if the request just goes to an inbox that is frequently checked by a list administrator who manually processes the unsubscribe-requests?

And what about the web-link? Does it have to point to a script that will unsubscribe the recipient there and then, or can it just point to the webpage with an unsubscribe form?

1

There are 1 answers

0
Synchro On BEST ANSWER

You can handle this how you like, however, you should also be aware of the List-Unsubscribe-Post header (defined in RFC8058) too, as it makes you far less prone to accidental unsubscribes caused by mail scanners.

I'd really recommend processing these automatically. It's not that difficult. The URLs in list-unsubscribe should be entirely self-contained, that is, you should embed all the data you need (for example a hash of a unique user identifier, and a mailing list ID) into the URLs, so for HTTP you might use:

'<https://www.example.com/listunsub/' . $userid .'/' . $listid . '>'

You could configure a rewrite in your web server to map that URL pattern to appropriate vars in your PHP script and do the necessary database operations to remove them from the mailing list.

For email it's a bit different:

'<mailto:listunsub-' . userid . '-' . $listid . '@example.com .'>'

For this last format you would configure your mail server to spot the 'listunsub-' prefix and use that to pipe the message into a script which could extract the user and list IDs. Notice that you don't need a subject or a message body - the address itself contains all you need, and that means that a receiver doesn't have to write a message - their mail client can simply send an empty message to the address and you will have enough info to work with.