當用戶從網站訂閱新聞時,他會在郵件中收到一封歡迎信,其中包含一個問題,他真的想訂閱新聞嗎?
信中還有一個按鈕,確認他同意時事通訊。
我怎樣才能使當我從電子郵件中單擊此按鈕時,我的資料庫中的值會更新?
這是我的郵件表格 welcome.blade.php
Welcome, User
<form action="{{route('welcome', $data->hash)}} method="POST">@csrf
<button type="submit">Click me</button>
</form>
控制器
public function welcome($hash) {
\DB::table('config')->where('hash', $hash)->update(['agree' => 1]);
路線
Route::post('welcome', 'WelcomeController@welcome')->name('welcome')
uj5u.com熱心網友回復:
不允許/建議在電子郵件中嵌入表格。這是一個安全風險。電子郵件客戶端只會警告收件人潛在的危險并禁用該表單。
您需要在電子郵件內容中添加指向您的應用程式的鏈接。
<a href="http://yourapp.com/add-consent/{$token}">click me</a>
當用戶點擊下面的 URL 時,路由將會命中。
Route::post('/add-consent/{token}', 'WelcomeController@welcome')->name('welcome');
在動作中根據令牌識別用戶并執行動作。
public function welcome($token) {
// Identify user based on token and perform the action...
\DB::table('config')->where('hash', $token)->update(['agree' => 1]);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/416424.html
標籤:
