One click unsubscribe button?
-
“Subscribe” buttons are simple to add. But is it possible to have an one-click “Unsubscribe” button (with a field for the user email) that does not go to the confirmation page?
I have a private site where all users are registered and logged in, and from other questions I have posted in this support forum, I can determine the logged in user, the list ID and their email.
There is a nonce in the unsubscribe link in the emails, which I assume is the encrypted user’s email address. So is a one click unsubscribe button – with a field for the user email – possible via the API or SQL?
-
Hello there @bluedogranch
Thanks for reaching out! I appreciate the details you’ve shared about your setup, and I understand that you’d like to implement a one-click unsubscribe button that does not require confirmation.
How MailPoet Handles Unsubscribes:
Currently, MailPoet and the MailPoet Sending Service support two standard unsubscribe methods:
- One-Click Unsubscribe via the List-Unsubscribe Email Header: This is available in certain email clients (like Gmail or Outlook). It allows users to unsubscribe directly from their email client without visiting the website.
- Unsubscribe Link in Emails: The standard “Unsubscribe” link in emails redirects the user to a confirmation page on your site, where they need to confirm their choice.
Options for Your Use Case:
Since you have a private site where users are logged in, and you can determine the user’s email and list ID, here’s what you can do:
Customizing the Plugin to Skip the Confirmation Page
- By default, MailPoet requires confirmation, but you can modify this behavior with custom code.
- You’d need to adjust how MailPoet processes the unsubscribe request, potentially by modifying the nonce validation or calling the API directly.
- Custom development like this is outside our scope of support, but you can hire a developer through Codeable for expert assistance.
Using the MailPoet API for One-Click Unsubscribe
- You could create a custom unsubscribe endpoint that processes user emails and removes them from a specific list without additional confirmation.
- MailPoet provides several Subscriber API that can be leveraged for this.
Direct Database Query (Not Recommended)
- You can technically remove subscribers from the database via SQL, but this is not recommended, as it could cause issues with MailPoet’s internal tracking.
- If you go this route, ensure you make a full site backup before making any direct changes.
Next Steps:
- If you’d like to explore the API route, I recommend checking the MailPoet API documentation.
- If you prefer a custom-coded solution, hiring a developer via Codeable would be the best approach.
I hope this is helpful.
Also Ján Mikláš @neosinner
Ojoma, it’s sort of helpful 🙁 But it’s more of an overview.
What is a specific example of a function that allows a one-click unsubscribe button? With no redirect to a confirmation page?
I see this https://github.com/mailpoet/mailpoet/blob/trunk/doc/api_methods/UnsubscribeGlobally.md
And I came across this snippet from https://gist.github.com/nickkraakman/0c353c161715a38cb808a14abfc24313
$subscriber = \MailPoet\API\API::MP('v1')->unsubscribeFromLists($subscriber_data['email'], $remove_from_lists, $options);which seems to be part of a function to unsubscribe, but beyond that, I’m puzzled.
Thanks for any help you can offer.
@bluedogranch
unsubscribeFromListsis a bit different, because it will leave the subscriber subscribed in general, but will only unsubscribe them from a specific list.You need to use
unsubscribemethod you linked to. I haven’t tested it, but this code should work:<?php
if (class_exists(\MailPoet\API\API::class)) {
// Initialize the MailPoet API
$mailpoet_api = \MailPoet\API\API::MP('v1');
try {
// The email address of the subscriber you want to unsubscribe
$subscriber_email = 'example@example.com';
// Call the unsubscribe method with the email address
$result = $mailpoet_api->unsubscribe($subscriber_email);
// The result will contain the updated subscriber data
// You can check the status to confirm the unsubscribe was successful
if ($result['status'] === 'unsubscribed') {
echo "Successfully unsubscribed subscriber with email: " . $subscriber_email;
}
} catch (\MailPoet\API\MP\v1\APIException $e) {
// Handle specific MailPoet API exceptions
switch ($e->getCode()) {
case 4:
echo "Error: Subscriber with email " . $subscriber_email . " does not exist.";
break;
case 24:
echo "Error: Subscriber with email " . $subscriber_email . " is already unsubscribed.";
break;
default:
echo "Error: " . $e->getMessage();
}
} catch (\Exception $e) {
// Handle any other unexpected errors
echo "Unexpected error: " . $e->getMessage();
}
}
?>Thanks! That’s a very comprehensive example of how it can work. I’m just learning this stuff 🙂
This is part of what I am using right now:
if ( class_exists( \MailPoet\API\API::class ) ) {
$mailpoet_api = \MailPoet\API\API::MP( 'v1' );
$subscriber = $mailpoet_api->getSubscriber( $loggedinemail );
$unsubscribe_user = $mailpoet_api->unsubscribe($loggedinemail);
if ( $subscriber[ 'status'] == 'subscribed' ) {
echo "<div class='currently-subscribed'>You are currently subscribed to receive new post emails.
// how do I fire the $unsubscribe_user with a button?
<button class='unsubscribe'>Unsubscribe here</button></div>"
;
} else {
echo "<hr class='aeaeae'><div style='font-size:18px;line-height:1.2;padding-top:10px;text-align:center'>You're not subscribed to receive new post emails.</div>";
}
}
}This probably doesn’t have much to do with MailPoet API and may be basic PHP, but what is a basic example of how I can “fire”
$unsubscribe_user = $mailpoet_api->unsubscribe($loggedinemail);from a button?Hi @bluedogranch, unfortunately, helping with MailPoet-unrelated PHP functions is out of the scope of free support.
<span style=”box-sizing: border-box; margin: 0px; padding: 0px;”>I recommend trying out ChatGPT (free) or Cursor (free trial), as both can easily handle this sort of question</span> and even any follow-ups you might have.
Thanks! I’ll check those out 🙂
The topic ‘One click unsubscribe button?’ is closed to new replies.