Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Newsletter-v0.1.1 unsubscribe not working.

Go to End

14 Posts   5261 Views


Community Member, 30 Posts

4 March 2009 at 2:16pm

Edited: 04/03/2009 2:24pm

I have installed a fresh version of Silverstripe 2.3 along with the Newsletter-v0.1.1 module. I have been able to create newsletter mailing list and got the subscribe system to work. Any new subscribers appear correctly under the Mailing List group in the security tag and under the Mailing List in the Newsletter tab of the CMS.

However, using the '/unsubscribe' url things start to go wrong. I am correctly taken to a request for my email to be input, then the checkbox for the mailing list that I am subscribed to comes up. Go through this bit and then it just goes to a blank page. Refreshing the CMS, I can see that I have not been unsubscribed.

When using the '/unsubscribe/(email)/(groupID)' url, just goes to a blank page - no confirmation or error message. Again, I am not unsubscribed from the Mailing List when I check back in the CMS.

It almost seems like some functions of the Unsubscribe.php file are being called but others are not (?!)

Any help here would be much appreciated.


Community Member, 791 Posts

11 March 2009 at 10:17am

Edited: 11/03/2009 10:24am

Confirmed, I bumped into this as well...

Nasty bug , since we have the newsletter module running in production ( I know , I know .. I'm bad.... it is only 0.1.1 ) ...

Did you already create a ticket for this ?

The unsubscribe link that gets send in the mail _does_ work properly for me , so for example : does work.

It is just the that does not work for me.


Community Member, 3 Posts

17 April 2009 at 9:34pm

Edited: 17/04/2009 9:40pm


i has just edited the code from the newsletter module, that the unsubscribe url can be used to remove the entered user!

The problem what i've found is, the forms cut of the mailaddress in the header, so i just change it to the member id and edit the data functions. Here the changes from me:


function unsubscribe($data, $form) {

		$email = $this->urlParams['Email'];
//		Change to get Data by ID
//		$member = DataObject::get_one( 'Member', "Email = '{$email}'" );
		$member = DataObject::get_by_id( 'Member', $email );

//		Change to get Data by ID
//        	$member = DataObject::get('Member', "`EmailAddress` = '$email'");
        	$member = DataObject::get_by_id('Member', $email);

        if( $data['MailingLists'] ) {
           foreach( array_keys( $data['MailingLists'] ) as $listID ){
           		$nlType = DataObject::get_by_id( 'NewsletterType', $listID );
           		$nlTypeTitles[]= $nlType->Title;
              $this->unsubscribeFromList( $member, DataObject::get_by_id( 'NewsletterType', $listID ) );
           $sORp = (sizeof($nlTypeTitles)>1)?"newsletters ":"newsletter ";
           //means single or plural
           $nlTypeTitles = $sORp.implode(", ", $nlTypeTitles);
	         $url = "unsubscribe/done/".$member->Email."/".$nlTypeTitles;
        } else {
	        $form->addErrorMessage('MailingLists', _t('Unsubscribe.NOMLSELECTED', 'You need to select at least one mailing list to unsubscribe from.'), 'bad');


class Unsubscribe_MailingListForm extends Form {
	protected $memberEmail;

	/****Create an ID-Environment variable****************/
	protected $memberID;

	function __construct( $controller, $name, $member, $email ) {

    	if($member) {
		$this->memberEmail = $member->Email;

		/*****Load the Member.ID to the variable**************/
		$this->memberID = $member->ID;
        $fields = new FieldSet(); 
        $actions = new FieldSet();
        if($member) {
	        // get all the mailing lists for this user
	        $lists = $this->getMailingLists( $member );
        } else {
        	$lists = false;
        if( $lists ) {
	    $fields->push( new LabelField('SubscribedToLabel', _t('Unsubscribe.SUBSCRIBEDTO', 'You are subscribed to the following lists:')) );
            foreach( $lists as $list ) {
                $fields->push( new CheckboxField( "MailingLists[{$list->ID}]", $list->Title ) );
            $actions->push( new FormAction('unsubscribe', _t('Unsubscribe.UNSUBSCRIBE', 'Unsubscribe') ) );
        } else {
	    $fields->push( new LabelField('NotSubscribedToLabel',sprintf(_t('Unsubscribe.NOTSUBSCRIBED', 'I\'m sorry, but %s doesn\'t appear to be in any of our mailing lists.'), $email) ) );   
        parent::__construct( $controller, $name, $fields, $actions );
    function FormAction() {
		/**** Change the FormAction Button to submit the ID******/
		//return $this->controller->RelativeLink() . "index/{$this->memberEmail}?executeForm=" . $this->name;
		return $this->controller->RelativeLink() . "unsubscribe/{$this->memberID}/";
    protected function getMailingLists( $member ) {
        // get all the newsletter types that the member is subscribed to
        return DataObject::get( 'NewsletterType', "`MemberID`='{$member->ID}'", null, "LEFT JOIN `Group_Members` USING(`GroupID`)" );  

i hope this is helpful to use the newsletter module completly.

greets Enno


Community Member, 95 Posts

23 May 2009 at 8:32am

Edited: 23/05/2009 8:34am

using the code above, i got the following error once i check off which newsletters i want to unsubscribe from:

Missing argument 2 for Unsubscribe_Controller::unsubscribe(),
function unsubscribe($data, $form) {
$email = $this->urlParams['Email'];
//      Change to get Data by ID
//      $member = DataObject::get_one( 'Member', "Email = '{$email}'" );
$member = DataObject::get_by_id( 'Member', $email );

I'm sure there's a better way to do this, but i got around it by modifying the unsubscribe function as follows:
function unsubscribe($data, $form = null) {

I'm not sure what the best way to fix this problem is though. any thoughts?

Big Bang Creative

Community Member, 92 Posts

11 June 2009 at 2:20am

Did anyone fix this? I have the same problem, the link just eventually submits to a blank page and nothing happens.

Gravitational FX

Community Member, 22 Posts

22 June 2009 at 7:55am

Hi there.

If you've got a spare couple of minutes, could you fun through how to install the newsletter module under SS2 .3.0
I'm very new to SS and cannot get this newsletter module to run.

There seems to be a newsletterv0.1.1 and also a tar which extracts to "modules\newsletter..."

Don't really know which files to add where.


Chris Rae

Community Member, 17 Posts

30 January 2010 at 6:03pm

Edited: 30/01/2010 6:36pm

I've just finished fixing the unsubscribe bug in the Newsletter module. It's not pretty, but then neither is the Newsletter module.

All you should need do is replace the 'Unsubscribe.php' file that comes as part of the newsletter module in the /code folder with this one.

I've only tested this using SS 2.3.3 but there's no funny business going on so it should be sweet with other versions.


25 Posts

11 February 2010 at 11:33pm

Edited: 11/02/2010 11:34pm

Thank you Chris,
I actually started debugging but with your code it works now.
There is still a typo left in translation:
I think in line 178 it should be

	    $fields->push( new LabelField('SubscribedToLabel', _t('Unsubscribe.SUBSCRIBEDTO', 'You are subscribed to the following lists:')) );

instead of
	    $fields->push( new LabelField('SubscribedToLabel', _t('Unsubcribe.SUBSCRIBEDTO', 'You are subscribed to the following lists:')) );

Anyway, the functionality works also without that ;-)

Go to Top