What are some best practices for handling user data in PHP, such as unsubscribing from newsletters?

When handling user data in PHP, it's important to provide users with a way to unsubscribe from newsletters to comply with privacy regulations and respect user preferences. One best practice is to include an unsubscribe link in the newsletters that users can click to easily opt-out. Additionally, ensure that user data is securely stored and that unsubscribed users are properly removed from the mailing list.

<?php
// Check if the user has clicked the unsubscribe link
if(isset($_GET['unsubscribe'])) {
    // Code to remove user from mailing list (e.g. update database)
    echo "You have been successfully unsubscribed from our newsletter.";
} else {
    echo "To unsubscribe from our newsletter, click <a href='unsubscribe.php?unsubscribe=true'>here</a>.";
}
?>