Handling of List-Unsubscribe callbacks on server

拈花ヽ惹草 提交于 2021-02-11 14:18:30

问题


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:unsubscribe@example.com?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:


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.



来源:https://stackoverflow.com/questions/52628287/handling-of-list-unsubscribe-callbacks-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!