Is there are away to detect an unsubscribe using code.

pinakin patel

New Member
I need to detect when someone unsubscribes from a list so that downstream applications can also pick this up to remove them.
I could possibly use the API to check every subscriber for their status but thought there might be a better way?
 
@pinakin patel - yes there is, 2 actually :)

1. You can edit your list settings and make it notify you when somebody unsubscribes from your list, then mailwizz will send you an email to your selected email address.

2. When somebody unsubscribes, mailwizz can send the information to a url of your choice.
You have to actually enable the "List form custom webhooks" extension then go to your list pages and in the unsubscribe page you will have an option to enter the url where mailwizz will post this information and select the method the data will be sent, either GET or POST.

And this is why mailwizz rocks :D
 
Just some quick feedback on this. When I use the post method on the webhook this this never triggers a call to my script. However a get method does.
 
Where do you find the unsubscribe page where you can set the URL and GET/POST option?

Backend/List Page Types nor
Front end/Lists/‘update list’ and ‘actions when unsubsribe’
Seem not to have any settings

Backend/extend/extension/list form custom web hooks is ticked.

Thank you.
 
Thank you - now active :-)

Where do you find the unsubscribe page where you can set the URL and GET/POST option?
 
@Jukkis - in customer area select your list -> Pages -> you have Custom webhooks at the bottom of page.
 
Ok found the webhooks page in the FrontEnd / Lists and then click Pages. On the top right dropdown box select 'Unsubscribe Confirmation' and the webhooks are there.

However I still have an issue to get the webhooks to work. I sent a test email list out to myself, and then 'Usubscribed' it on the list by using the unsubscribe link provided on the email. My email address has been unsubscribed when I look at the lists/subscriber info in the Mailwizz.

However my web hooks link to php does not seem to work.

My webhooks have been set by the following URL (with GET request type):-
http://www.mydomain.com/mail-server/unsubscribe.php?email=EMAIL

Note: Email is enclosed in square brackets above (but If I post this message like it copies my message multiple times). Also tried wtihrout brackets or in lower case without brackets.

On my unsubscribe.php has line
$email = $_GET["email"];
And then code to action the email unsubscribe

But when I unsubscribe this code does not seem to run. If I use directly code
http://www.mydomain.com/mail-server/unsubscribe.php?email=john.doe@gmail.com

The unsubscribe.php runs correctly.

Any suggestions
 
OK - still no luck. Tried both POST and GET request types
An in my php file
$email = $_GET['EMAIL']
$email = $_POST['EMAIL']

EMAIL is in capital $_GET['EMAIL'] statement and inside single quote. Not sure if that actually matters (or if it is case sensitive). Is there a way to debug to see what the mailwizz sends as a message or if the URL has been actioned?
 
Is there a way to debug to see what the mailwizz sends as a message or if the URL has been actioned?
You could log the requests in your unsubscribe.php file. smth like:
PHP:
// make sure the logs folder is chmoded to 0777
file_put_contents('./logs/' . time() . '.txt', json_encode($_GET) . ' ' . json_encode($_POST));
How does the Mailwizz know what tags needs to be appended to the the URL?
It will append all the custom fields that particular subscriber has.
 
@Jukkis - I think there's more to it, i have just looked in the code, and it seems we're sending the data in _GET in a special key, that is 'subscriber', so can you check:
Code:
$email = isset($_GET['subscriber']['email']) ? $_GET['subscriber']['email'] : '';
and let me know if that makes any difference ?
 
The returned JSON format is as follows:-
{"data":{
"action":"unsubscribe-confirm",
"list":{"list_uid":"ry869j06vv8c1","name":"test"},
"subscriber":{"subscriber_uid":"lg025xmvvoaed","email":"john.doe@gmail.com"}
}
}

[]

Therefore on your php-code you will need to use $_GET as follows to get the email address
$email = $_GET['data']['subscriber']['email'];

Then it works!
 
Back
Top