Can i change the functionality of the unsubscribe link to blacklist the recipient?

jhall95

Member
Currently using the [direct_unsubscribe_url] as an unsubscribe button but I would like it is if it would blacklist the recipient to prevent a campaign from a different user emailing them or some kind of accidental resubscribe
 
That's not possible without custom coding, you can add this code in apps/init-custom.php (create the file if missing):
Code:
<?php

Yii::app()->hooks->addAction('frontend_lists_after_track_campaign_unsubscribe', function($controller, CampaignTrackUnsubscribe $track) {
    $track->subscriber->addToBlacklist("Your message here...");
});
Please note I haven't tested this, so make sure you do.
 
I tried but it didn't work for me :(

I tested by sending a test mail from a campaign by click to send test button, and used unsub link which defined as [UNSUBSCRIBE_URL].

As a result, my email is unsub from the list but didn't black listed.

I should've seen it on admin panel > email blacklist right?

I would be more than appreciate if we can solve it.

Lastly here is my edit in init-custom.php

1673622051611.png

thanks.
 
@Melihck - of course, because if you are not confirmed anymore you can't be added to the blacklist, my bad on this.
Please see updated code:

PHP:
Yii::app()->hooks->addAction('frontend_lists_after_track_campaign_unsubscribe', function($controller, CampaignTrackUnsubscribe $track) {
    $exists = EmailBlacklist::model()->findByAttributes(['email' => $track->subscriber->email]);
    if (!empty($exists)) {
        return;
    }
    
    $model = new EmailBlacklist();
    $model->email         = $track->subscriber->email;
    $model->subscriber_id = $track->subscriber_id;
    $model->reason        = 'Add your message here';
    $model->save(false);
    
    $track->subscriber->saveStatus(ListSubscriber::STATUS_BLACKLISTED);
});
 
Hello, I'm using this code to add all unsubscribes to the blacklist, and it works perfectly.

It ensures a customer never emails an unsubscribe again, I think most peoples expectation of an unsubscribe is they never receive a email from that company again.

BUT there is one issue with this method for me.

It stops my other customers emailing them as well.

A perfect solution would be an unsubscribe blacklist per customer.

Or a workaround would be:

a) Force unsubscribes to unsubscribe from all of the other lists owned by that customer, and copy to a list called "Unsubscribes"
b) When import new subscribers, don't import if they exist in this customers "Unsubscribes" List.

Is there a way of achieving this?

Thankyou
 
@jonathanm841 - You could potentially make use of the per-customer email blacklist, so instead of injecting the email into the global backlist, you add it in the customer blacklist.
To do this, first enable per-customer email blacklist from Backend > Settings > Customers > Lists > Use own blacklist (same in customer group).
Then modify the code as:
PHP:
Yii::app()->hooks->addAction('frontend_lists_after_track_campaign_unsubscribe', function($controller, CampaignTrackUnsubscribe $track) {
    $exists = CustomerEmailBlacklist::model()->findByAttributes([
        'email' => $track->subscriber->email,
        'customer_id' => $track->campaign->customer_id,
    ]);
    if (!empty($exists)) {
        return;
    }
    
    $model = new CustomerEmailBlacklist();
    $model->email         = $track->subscriber->email;
    $model->customer_id      = $track->campaign->customer_id;
    $model->reason        = 'Add your message here';
    $model->save(false);
    
    $track->subscriber->saveStatus(ListSubscriber::STATUS_BLACKLISTED);
});
 
I didn't know there was a customer blacklist! Thats awesome.

Will the system use the blacklist and customer blacklist? Or now only customer blacklist?
 
@jonathanm841 - You could potentially make use of the per-customer email blacklist, so instead of injecting the email into the global backlist, you add it in the customer blacklist.
To do this, first enable per-customer email blacklist from Backend > Settings > Customers > Lists > Use own blacklist (same in customer group).
Then modify the code as:
PHP:
Yii::app()->hooks->addAction('frontend_lists_after_track_campaign_unsubscribe', function($controller, CampaignTrackUnsubscribe $track) {
    $exists = CustomerEmailBlacklist::model()->findByAttributes([
        'email' => $track->subscriber->email,
        'customer_id' => $track->campaign->customer_id,
    ]);
    if (!empty($exists)) {
        return;
    }
   
    $model = new CustomerEmailBlacklist();
    $model->email         = $track->subscriber->email;
    $model->customer_id      = $track->campaign->customer_id;
    $model->reason        = 'Add your message here';
    $model->save(false);
   
    $track->subscriber->saveStatus(ListSubscriber::STATUS_BLACKLISTED);
});
This works perfect. Is there a way for me to copy the Hard Bounces from the customer blacklist to master blacklist?
 
This is great!
@jonathanm841 - You could potentially make use of the per-customer email blacklist, so instead of injecting the email into the global backlist, you add it in the customer blacklist.
To do this, first enable per-customer email blacklist from Backend > Settings > Customers > Lists > Use own blacklist (same in customer group).
Then modify the code as:
PHP:
Yii::app()->hooks->addAction('frontend_lists_after_track_campaign_unsubscribe', function($controller, CampaignTrackUnsubscribe $track) {
    $exists = CustomerEmailBlacklist::model()->findByAttributes([
        'email' => $track->subscriber->email,
        'customer_id' => $track->campaign->customer_id,
    ]);
    if (!empty($exists)) {
        return;
    }
   
    $model = new CustomerEmailBlacklist();
    $model->email         = $track->subscriber->email;
    $model->customer_id      = $track->campaign->customer_id;
    $model->reason        = 'Add your message here';
    $model->save(false);
   
    $track->subscriber->saveStatus(ListSubscriber::STATUS_BLACKLISTED);
});
Will this be added in some ways more natively within one of the next updates? So we can decide what type of behavior a list unsubscribe should be doing.
 
Will this be added in some ways more natively within one of the next updates?
We do not plan to change the way the app unsubscribe process works, so it will not change in the app.

However, the changes you applied will be safe for upgrades.
 
We do not plan to change the way the app unsubscribe process works, so it will not change in the app.

However, the changes you applied will be safe for upgrades.
Great! What I was referring to is to have an option in the settings to decide the behavior of when someone unsubscribe.
For example, have the option to:
- Unsubscribe only from list
- Unsubscribe and add email to blacklist (if there's no customer specific blacklist, add email to global blacklist)
 
Back
Top