# Unsubscribe link obfusucate email and campaignid via php

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-to-obfuscate-the-ema" jsaction="rcuQ6b:&WCOIpc_7|npT2md" jscontroller="zcfIf" jsuid="WCOIpc_7" style="font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 0px 0px 16px; color: rgb(10, 10, 10); margin-inline: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">To obfuscate the email and campaign ID in an unsubscribe link using PHP, you should **encode the data into a single, signed token (e.g., using `hash_hmac`)** rather than including the raw values in the URL query parameters. This approach prevents bots from harvesting emails and ensures the data's integrity.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="WCOIpc_c,WCOIpc_d"><span class="vKEkVd" data-animation-atomic="" data-processed="true" data-wiz-attrbind="class=WCOIpc_b/TKHnVd" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="e8d6719e-034a-4820-9d19-66adf6000c33" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQye0OegQIARAB" data-wiz-attrbind="disabled=WCOIpc_b/C5gNJc;aria-label=WCOIpc_b/bOjMyf;class=WCOIpc_b/UpSNec" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&WCOIpc_g|npT2md" jscontroller="KHhJQ" jsuid="WCOIpc_g" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-1.-generating-the-ob" jscontroller="a7qCn" jsuid="WCOIpc_h" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 24px 0px 12px; font-weight: 600; margin-inline: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">1. Generating the Obfuscated Link<span class="txxDge notranslate" data-processed="true" data-wiz-uids="WCOIpc_j,WCOIpc_k" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" data-wiz-attrbind="class=WCOIpc_i/TKHnVd" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="df878eb6-5bd2-4e25-8e32-bf386e2a5251" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQye0OegQIAhAA" data-wiz-attrbind="disabled=WCOIpc_i/C5gNJc;aria-label=WCOIpc_i/bOjMyf;class=WCOIpc_i/UpSNec" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Y3BBE" data-hveid="CAMQAA" data-processed="true" data-sfc-cp="" id="bkmrk-first%2C-you-need-a-se" jsaction="rcuQ6b:&WCOIpc_l|npT2md" jscontroller="zcfIf" jsuid="WCOIpc_l" style="font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 12px 0px 16px; color: rgb(10, 10, 10); margin-inline: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">First, you need a secret key stored securely on your server. When generating the email, you'll create a unique token for each recipient by combining the email and campaign ID and signing it with your secret key.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="WCOIpc_n,WCOIpc_o"><span class="vKEkVd" data-animation-atomic="" data-processed="true" data-wiz-attrbind="class=WCOIpc_m/TKHnVd" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="59a06813-caa8-4348-a38d-592379df817b" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQye0OegQIAxAB" data-wiz-attrbind="disabled=WCOIpc_m/C5gNJc;aria-label=WCOIpc_m/bOjMyf;class=WCOIpc_m/UpSNec" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&WCOIpc_p|npT2md" jscontroller="KHhJQ" jsuid="WCOIpc_p" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div class="r1PmQe" data-hveid="CAQQAA" data-processed="true" data-wiz-uids="WCOIpc_r,WCOIpc_s,WCOIpc_t" id="bkmrk-php" jscontroller="HP6Sjf" jsuid="WCOIpc_q" style="font-family: 'Google Sans', Arial, sans-serif; color: rgb(0, 29, 53); margin: 24px 0px 32px; font-weight: 400; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); border-image: none 100% / 1 / 0 stretch; border-radius: 8px; overflow: hidden; padding: 0px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="vVRw1d" data-processed="true" style="font-weight: 500; font-size: 20px; line-height: 26px; background-color: rgb(229, 237, 255); height: 34px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1.2px solid rgb(169, 172, 170); padding: 0px 4px 0px 16px;">php<button aria-label="Copy code text to clipboard." class="Ev0C3d" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQopQPegQIBBAB" style="margin: 0px; background: none; color: rgb(5, 40, 97); border: none; padding: 4px; font: inherit; outline: 0px; cursor: pointer;"><svg fill="currentColor" height="20px" jscontroller="ZfypCb" jsuid="WCOIpc_u" viewbox="0 -960 960 960" width="20px"><path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"></path></svg></button></div><div class="pCTyYe" data-processed="true" dir="ltr" style="unicode-bidi: isolate; font-size: 14px; line-height: 22px; overflow-x: auto; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); padding: 2px 16px;"></div></div></div></div>```
<?php
// Define a strong, secret key in your configuration
define('SECRET_KEY', 'your_very_strong_server_secret_key_here');

// Data to obfuscate
$email = 'useremail@example.com';
$campaign_id = 123;

// Combine data into a single string
$data = $email . '|' . $campaign_id;

// Generate a signature (HMAC) of the data
$signature = hash_hmac('sha256', $data, SECRET_KEY);

// Base64-url encode the data for safe URL transmission
$encoded_data = rtrim(strtr(base64_encode($data), '+/', '-_'), '=');

// Create the final token (data.signature format)
$token = $encoded_data . '.' . $signature;

// Construct the unsubscribe link
$unsubscribe_url = "yourdomain.com" . urlencode($token);

echo '<a href="' . htmlspecialchars($unsubscribe_url) . '">Unsubscribe</a>';
?>

```

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--2" jsaction="rcuQ6b:&WCOIpc_w|npT2md" jscontroller="KHhJQ" jsuid="WCOIpc_w" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-2.-processing-the-li" jscontroller="a7qCn" jsuid="WCOIpc_x" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 24px 0px 12px; font-weight: 600; margin-inline: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">2. Processing the Link in `unsubscribe.php`<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="WCOIpc_10,WCOIpc_11"><span class="vKEkVd" data-animation-atomic="" data-processed="true" data-wiz-attrbind="class=WCOIpc_z/TKHnVd" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="9b5be7d3-be87-45e3-a520-755ba21bf049" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQye0OegQIBRAA" data-wiz-attrbind="disabled=WCOIpc_z/C5gNJc;aria-label=WCOIpc_z/bOjMyf;class=WCOIpc_z/UpSNec" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Y3BBE" data-hveid="CAYQAA" data-processed="true" data-sfc-cp="" id="bkmrk-when-a-user-clicks-t" jsaction="rcuQ6b:&WCOIpc_12|npT2md" jscontroller="zcfIf" jsuid="WCOIpc_12" style="font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 12px 0px 16px; color: rgb(10, 10, 10); margin-inline: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">When a user clicks the link, the `unsubscribe.php` script will validate the token before processing the request.<span class="txxDge notranslate" data-processed="true" data-wiz-uids="WCOIpc_15,WCOIpc_16" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" data-wiz-attrbind="class=WCOIpc_14/TKHnVd" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="238f835f-09f4-4b03-b745-fe5e1bedbaee" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQye0OegQIBhAB" data-wiz-attrbind="disabled=WCOIpc_14/C5gNJc;aria-label=WCOIpc_14/bOjMyf;class=WCOIpc_14/UpSNec" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--3" jsaction="rcuQ6b:&WCOIpc_17|npT2md" jscontroller="KHhJQ" jsuid="WCOIpc_17" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div class="r1PmQe" data-hveid="CAcQAA" data-processed="true" data-wiz-uids="WCOIpc_19,WCOIpc_1a,WCOIpc_1b" id="bkmrk-php-1" jscontroller="HP6Sjf" jsuid="WCOIpc_18" style="font-family: 'Google Sans', Arial, sans-serif; color: rgb(0, 29, 53); margin: 24px 0px 32px; font-weight: 400; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); border-image: none 100% / 1 / 0 stretch; border-radius: 8px; overflow: hidden; padding: 0px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="vVRw1d" data-processed="true" style="font-weight: 500; font-size: 20px; line-height: 26px; background-color: rgb(229, 237, 255); height: 34px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1.2px solid rgb(169, 172, 170); padding: 0px 4px 0px 16px;">php<button aria-label="Copy code text to clipboard." class="Ev0C3d" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQopQPegQIBxAB" style="margin: 0px; background: none; color: rgb(5, 40, 97); border: none; padding: 4px; font: inherit; outline: 0px; cursor: pointer;"><svg fill="currentColor" height="20px" jscontroller="ZfypCb" jsuid="WCOIpc_1c" viewbox="0 -960 960 960" width="20px"><path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"></path></svg></button></div><div class="pCTyYe" data-processed="true" dir="ltr" style="unicode-bidi: isolate; font-size: 14px; line-height: 22px; overflow-x: auto; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); padding: 2px 16px;"></div></div></div></div>```
<?php
// Define the same secret key used for generation
define('SECRET_KEY', 'your_very_strong_server_secret_key_here');

if (isset($_GET['token'])) {
    $token = $_GET['token'];
    $parts = explode('.', $token);

    if (count($parts) === 2) {
        $encoded_data = $parts[0];
        $received_signature = $parts[1];

        // Decode the data part
        $data = base64_decode(strtr($encoded_data, '-_', '+/'));

        // Re-calculate the expected signature
        $expected_signature = hash_hmac('sha256', $data, SECRET_KEY);

        // Verify the signature
        if (hash_equals($expected_signature, $received_signature)) {
            // Token is valid and has not been tampered with
            list($email, $campaign_id) = explode('|', $data);

            // Validate the email format and campaign ID type
            if (filter_var($email, FILTER_VALIDATE_EMAIL) && is_numeric($campaign_id)) {
                // Perform the unsubscribe action (e.g., update your database)
                // Example: update_user_status($email, $campaign_id, 'unsubscribed');
                echo "You have been successfully unsubscribed from campaign " . htmlspecialchars($campaign_id) . ".";
            } else {
                echo "Invalid data in token.";
            }
        } else {
            // Invalid signature - potential tampering
            echo "Invalid or tampered unsubscribe link.";
        }
    } else {
        echo "Invalid token format.";
    }
} else {
    echo "No token provided.";
}

// Helper function for secure string comparison (prevents timing attacks)
function hash_equals_safe($str1, $str2) {
    if(strlen($str1) !== strlen($str2)) {
        return false;
    }
    $res = 0;
    for ($i = 0; $i < strlen($str1); $i++) {
        $res |= ord($str1[$i]) ^ ord($str2[$i]);
    }
    return $res === 0;
}

// Use hash_equals_safe($expected_signature, $received_signature) in PHP < 5.6
if (!function_exists('hash_equals')) {
    function hash_equals($str1, $str2) {
        // ... implementation from above ...
        return hash_equals_safe($str1, $str2);
    }
}
?>

```

<div class="Y3BBE" data-hveid="CAgQAA" data-processed="true" data-sfc-cp="" id="bkmrk-this-method-securely" jsaction="rcuQ6b:&WCOIpc_1e|npT2md" jscontroller="zcfIf" jsuid="WCOIpc_1e" style="font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 12px 0px 16px; color: rgb(10, 10, 10); margin-inline: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">This method securely encodes the necessary information while preventing the raw email and campaign ID from being openly visible or easily abused.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="WCOIpc_1g,WCOIpc_1h"><span class="vKEkVd" data-animation-atomic="" data-processed="true" data-wiz-attrbind="class=WCOIpc_1f/TKHnVd" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="ed2127bc-4da8-4f80-b73c-671e82b61017" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQye0OegQICBAB" data-wiz-attrbind="disabled=WCOIpc_1f/C5gNJc;aria-label=WCOIpc_1f/bOjMyf;class=WCOIpc_1f/UpSNec" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--4" jsaction="rcuQ6b:&WCOIpc_1k|npT2md" jscontroller="KHhJQ" jsuid="WCOIpc_1k" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-best-practice" jscontroller="a7qCn" jsuid="WCOIpc_1l" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 24px 0px 12px; font-weight: 600; margin-inline: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Best Practice<span class="txxDge notranslate" data-processed="true" data-wiz-uids="WCOIpc_1n,WCOIpc_1o" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" data-wiz-attrbind="class=WCOIpc_1m/TKHnVd" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="5f658040-a9c8-4391-bb3f-1d9886e0037c" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQye0OegQICRAA" data-wiz-attrbind="disabled=WCOIpc_1m/C5gNJc;aria-label=WCOIpc_1m/bOjMyf;class=WCOIpc_1m/UpSNec" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Y3BBE" data-hveid="CAoQAA" data-processed="true" data-sfc-cp="" id="bkmrk-consider-adding-the%C2%A0" jsaction="rcuQ6b:&WCOIpc_1p|npT2md" jscontroller="zcfIf" jsuid="WCOIpc_1p" style="font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 12px 0px 16px; color: rgb(10, 10, 10); margin-inline: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Consider adding the `List-Unsubscribe` header to your emails. This allows email clients (like Gmail or Outlook) to provide a native "Unsubscribe" button within their interface, improving deliverability and user experience.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="WCOIpc_1s,WCOIpc_1t"><span class="vKEkVd" data-animation-atomic="" data-processed="true" data-wiz-attrbind="class=WCOIpc_1r/TKHnVd" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="dbd2ba1c-8fce-4b92-b01b-f9fe67272d82" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQye0OegQIChAB" data-wiz-attrbind="disabled=WCOIpc_1r/C5gNJc;aria-label=WCOIpc_1r/bOjMyf;class=WCOIpc_1r/UpSNec" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--5" jsaction="rcuQ6b:&WCOIpc_1v|npT2md" jscontroller="KHhJQ" jsuid="WCOIpc_1v" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div class="r1PmQe" data-hveid="CA0QAA" data-processed="true" data-wiz-uids="WCOIpc_3k,WCOIpc_3l,WCOIpc_3m" id="bkmrk-php-2" jscontroller="HP6Sjf" jsuid="WCOIpc_3j" style="font-family: 'Google Sans', Arial, sans-serif; color: rgb(0, 29, 53); margin: 24px 0px 32px; font-weight: 400; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); border-image: none 100% / 1 / 0 stretch; border-radius: 8px; overflow: hidden; padding: 0px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="vVRw1d" data-processed="true" style="font-weight: 500; font-size: 20px; line-height: 26px; background-color: rgb(229, 237, 255); height: 34px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1.2px solid rgb(169, 172, 170); padding: 0px 4px 0px 16px;">php<button aria-label="Copy code text to clipboard." class="Ev0C3d" data-processed="true" data-ved="2ahUKEwjUiZrd2YiSAxVyyzgGHX46JykQopQPegQIDRAB" style="margin: 0px; background: none; color: rgb(5, 40, 97); border: none; padding: 4px; font: inherit; outline: 0px; cursor: pointer;"><svg fill="currentColor" height="20px" jscontroller="ZfypCb" jsuid="WCOIpc_3n" viewbox="0 -960 960 960" width="20px"><path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"></path></svg></button></div><div class="pCTyYe" data-processed="true" dir="ltr" style="unicode-bidi: isolate; font-size: 14px; line-height: 22px; overflow-x: auto; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); padding: 2px 16px;"></div></div></div></div>```
// When sending the email (using PHPMailer as an example):
$mail->addCustomHeader('List-Unsubscribe', '<yourdomain.com' . urlencode($token) . '>');
$mail->addCustomHeader('List-Unsubscribe-Post', 'List-Unsubscribe=One-Click'); // For one-click handling
```