setting up a preference sub/unsub area

emailwrks

Member
Hey,

I've been looking through mailwizz, and whilst i think it's just about do-able, i wanted to double check here first.

I will have the same subscriber in multiple product lists, I would like to be able to create a preference centre, subscribe or (mainly) unsubscribe, link and area. Where the user ticks or unticks what lists they want to be subscribed to and hit update/save.

I'm thinking this is the profile area really, but can someone confirm and the setup to use? Also what link to use in the unsubscribe link of the emails to access this preference centre?

many thanks!
 

twisted1919

Administrator
Staff member
Sure,

You can have a file, say unsubscribe.php with following contents in it:
(pseudocode mostly)
PHP:
<?php
if (!empty($_POST)) {
    $subscriber_uid = isset($_GET['subscriber']) ? $_GET['subscriber'] : null;
    if (!$subscriber_uid) {
        exit('please provide a valid subscriber');
    }
    $lists = isset($_POST['lists']) ? (array)$_POST['lists'] : array();
    $endpoint = new MailWizzApi_Endpoint_ListSubscribers();
    foreach ($lists as $list_uid) {
        $endpoint->unsubscribe($list_uid, $subscriber_uid);
    }
}
?>
<form action="" method="post">
   <input type="checkbox" name="lists[]" value="list uid 1"/> - First list <br />
  <input type="checkbox" name="lists[]" value="list uid 2"/> - Second list <br />
  <input type="checkbox" name="lists[]" value="list uid 3"/> - Third list <br />
  <input type="submit" value="Unsubscribe"/>
</form>
Then in your campaign, instead of using the default unsubscribe link, you will use:
http://www.domain.com/unsubscribe.php?subscriber=[SUBSCRIBER_UID] and once this link is clicked, the subscriber is taken to your page, where he can check the lists and when submitting the form, be unsubscribed from all he checked.
 

frm.mwz

Well-Known Member
Sure,

You can have a file, say unsubscribe.php with following contents in it:
(pseudocode mostly)
PHP:
<?php
if (!empty($_POST)) {
    $subscriber_uid = isset($_GET['subscriber']) ? $_GET['subscriber'] : null;
    if (!$subscriber_uid) {
        exit('please provide a valid subscriber');
    }
    $lists = isset($_POST['lists']) ? (array)$_POST['lists'] : array();
    $endpoint = new MailWizzApi_Endpoint_ListSubscribers();
    foreach ($lists as $list_uid) {
        $endpoint->unsubscribe($list_uid, $subscriber_uid);
    }
}
?>
<form action="" method="post">
   <input type="checkbox" name="lists[]" value="list uid 1"/> - First list <br />
  <input type="checkbox" name="lists[]" value="list uid 2"/> - Second list <br />
  <input type="checkbox" name="lists[]" value="list uid 3"/> - Third list <br />
  <input type="submit" value="Unsubscribe"/>
</form>
Then in your campaign, instead of using the default unsubscribe link, you will use:
http://www.domain.com/unsubscribe.php?subscriber=[SUBSCRIBER_UID] and once this link is clicked, the subscriber is taken to your page, where he can check the lists and when submitting the form, be unsubscribed from all he checked.
Would the part before the form code be meant to auto-generate a listing of 'lists the subscriber is on' (and then create that form code)?
 

emailwrks

Member
hey,

may be a bit of a n00b question but my php isn't wonderful.

so i have tested the above, and when clicking unsubscribe got this response;

Fatal error: Class 'MailWizzApi_Endpoint_ListSubscribers' not found in /home4/1234/public_html/domain.online/subscribepreference.php on line 8

what am i missing? Do i need to load up the SDK into the same location at all or specify anything with it. Also frm.mwz's question above is quite relevant too.

Many thanks!
 

emailwrks

Member
Ok reading a bit more into the Api stuff

Seems I have to reference the setup.php file in my other php file or combine the two.

Would this be a correct assumption?
 

emailwrks

Member
okay! i've gotten it to work in principle!

what i have stumbled upon however is that of course subscriber id's, for the same subscriber, are unique to every list, therefore when i am using;

http://site.online/subscribepreference.php?subscriber=ov1920hjgoa7f

as my preference center unsubscribe i want to control a subscriber across 3 lists, it will only find the subscriber in one list, and cannot possibly check for or unsubscribe in the other 2 lists.. What can i possibly do to work around this? Any way to use EMAIL and LIST ID instead to force an unsubscribe?

also anyway to show them as ticked, which in fact means they are subscribed in the first place?

many thanks
 

emailwrks

Member
im trying an example with this endpoint;

$response = $endpoint->emailSearch('LIST-UNIQUE-ID', 'EMAIL');

which i think will work email + list id, but my code is not working, when trying to click unsubscribe it is showing me the error message 'please provide a valid subscriber', so my PHP below is wrong, please can you let me know if this is a workable option and code correction?

<?php
require_once dirname(__FILE__) . '/setup.php';

if (!empty($_POST)) {
$EMAIL = isset($_GET['EMAIL']) ? $_GET['EMAIL'] : null;
if (!$EMAIL) {
exit('please provide a valid subscriber');
}
$lists = isset($_POST['lists']) ? (array)$_POST['lists'] : array();
$response = $endpoint->emailSearch('LIST-UNIQUE-ID', 'EMAIL');
foreach ($lists as $list_uid) {
$endpoint->unsubscribe($list_uid, $EMAIL);
}
}
?>
<form action="" method="post">
<input type="checkbox" name="lists[]" value="jr629ewf3ac61"/> - Master List <br />
<input type="checkbox" name="lists[]" value="pf930hxo155a0"/> - List2 <br />
<input type="checkbox" name="lists[]" value="aw311meyyed8a"/> - List3<br />
<input type="submit" value="Unsubscribe"/>
</form>

thanks a lot!
 

twisted1919

Administrator
Staff member
You have to access your script like:
http://site.online/subscribepreference.php?EMAIL=a@a.com
if you want the above script to work.
PHP:
<?php
require_once dirname(__FILE__) . '/setup.php';

if (!empty($_POST)) {
    $EMAIL = isset($_GET['EMAIL']) ? $_GET['EMAIL'] : null;
    if (!filter_var($EMAIL, FILTER_VALIDATE_EMAIL)) {
        exit('please provide a valid subscriber');
    }
    $lists = isset($_POST['lists']) ? (array)$_POST['lists'] : array();
    foreach ($lists as $list_uid) {
        $endpoint->unsubscribe($list_uid, $EMAIL);
    }
}
?>
<form action="" method="post">
<input type="checkbox" name="lists[]" value="jr629ewf3ac61"/> - Master List <br />
<input type="checkbox" name="lists[]" value="pf930hxo155a0"/> - List2 <br />
<input type="checkbox" name="lists[]" value="aw311meyyed8a"/> - List3<br />
<input type="submit" value="Unsubscribe"/>
</form>
 

emailwrks

Member
Hi, yes I already accessed it like so

But the script didn't do anything. Have I even got the php script correct?

- sorry just seen the script you entered is in fact different to my attempt, will give this a try

Thanks
 
Top