简体   繁体   English

如何在电子邮件中设置自己的“退订”按钮?

[英]How do I make my own “unsubscribe” button in an email?

I got a controller that sends an email with an array of variables, which includes the person's name and the timestamp they made a request. 我有一个控制器,该控制器发送带有一系列变量的电子邮件,其中包括该人的姓名和他们发出请求的时间戳。 The email sends an html file, and in the html file there has a "Click here to delete bla bla bla." 电子邮件发送了一个html文件,并且在html文件中有一个“单击此处删除bla bla bla”。 line. 线。 When the user clicks on the link, the link will send them to a controller that will delete their name from my database. 当用户单击链接时,该链接会将其发送到控制器,该控制器将从我的数据库中删除其名称。

Now, I'm not entirely sure how I'm supposed to do this. 现在,我不太确定该怎么做。 I could obviously do something like this: 我显然可以做这样的事情:

Click <a href='https://xxx.xx.xxx.xxx:8000/web/misc/request/delete/<?php echo $data['timestamp']; ?>/<?php echo $data['name']; ?>'> here</a> to delete bla bla bla.

Then, in my routing file, I'll have: 然后,在我的路由文件中,我将拥有:

Route::get('/web/misc/request/delete/{time}/{name}', 'EmailController@deleteRequest');

Then I can just query my database with the name and the timestamp, and viola, delete. 然后,我可以使用名称和时间戳查询数据库,然后中提琴删除。

But someone could easily just edit the name or timestamp in the URL, right? 但是有人可以轻松地编辑URL中的名称或时间戳,对吗?

This made me want to use POST, but I'm not entirely sure how I'm supposed to do that in this scenario. 这使我想使用POST,但是我不确定在这种情况下应该如何做。 I could just make a form, set some inputs to hidden, and then store the name and timestamp into those input values. 我可以制作一个表单,将一些输入设置为隐藏,然后将名称和时间戳存储到这些输入值中。 I haven't tried this yet because it sounds pretty hacky. 我还没有尝试过,因为它听起来很hacky。 Using a session also wouldn't work in this case, right? 在这种情况下,使用会话也不起作用,对吗? Would this be a good time to use cookies? 这是使用Cookie的好时机吗? Or should I use some sort of keys? 还是应该使用某种钥匙?

But someone could easily just edit the name or timestamp in the URL, right? 但是有人可以轻松地编辑URL中的名称或时间戳,对吗?

Yes

This made me want to use POST 这让我想使用POST

That wouldn't help. 那无济于事。 You would still depend entirely upon data under the control of the client. 您仍将完全依赖客户端控制下的数据。


Generate random alphanumeric strings to use an identifiers. 生成随机字母数字字符串以使用标识符。 Store it in your database with the rest of the data about the subscribed user. 将其与有关已订阅用户的其余数据一起存储在数据库中。 Include it in the URL. 将其包括在URL中。

When the request comes in, check that the email address being unsubscribed and matches the confirmation string in your database. 收到请求后,请检查电子邮件地址是否已取消订阅并与数据库中的确认字符串匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM