RSS Feed

Blog

Fixes and Tweaks for Newsletter Made Simple of CMS Made Simple

Fixes and Tweaks for Newsletter Made Simple of CMS Made Simple
Posted on May 8, 2010 by Stephen Owens
Tutorial and Code category
   [ Return ]

Newsletter Made Simple (NMS) for CMS Made Simple (CMSMS) is an easy to use bulk mailer, which I have been using for a few years now. In this blog post I will explain some of the functionality problems I have come across and the solutions I use to make NMS my bulk mailer of choice.

I have tired other bulk mailing programs, such as the very popular phpList, but it's nice to just have a native bulk mailer inside the content management system (CMS). A big thank you to lemkepf, calguy1000, and nuno for developing the NMS code. It just needed a few tweaks.

Newsletter Made Simple Version: 2.3.2

Each solution below has been checked and they all work with version 2.3.2 of NMS. All of the tweaks (problems and solutions) below were created when I was running version 2.2.3 of Newsletter Made Simple (NMS).

NMS Solutions With Links To The Fixes


Fix: Unsubscribe from all lists public and private

The Problem

Sometimes you want to have a private list of a select group of customers or site visitors. By default Newsletter Made Simple will not allow people on a private list to remove themselves.

If a user wants off a list they have the right to remove their email address from our bulk email lists regardless if it is public or private. In the United Sates we also have the CANSPAM laws for those business owners who just don't get that bulk emailing is infact not cheap bulk postal mail.

The Solution

Open the file: action.unsubscribe.php

Near line 75 find:

  1. $query = "SELECT A.listid FROM ".NMS_LIST_TABLE." A,
    ".
    
  2.   NMS_LISTUSER_TABLE." B WHERE A.listid = B.listid AND A.public =
    1
    
  3.   AND B.userid = ?";

Change it to:

  1. // modified to delete membership from all lists both public and private
    
  2. $query = "SELECT A.listid FROM ".NMS_LIST_TABLE." A,
    ".
    
  3.   NMS_LISTUSER_TABLE." B WHERE A.listid = B.listid
    
  4.   AND B.userid = ?";


Fix: Invalid argument when user doesn't select any lists in Preferences

This problem has been fixed in NMS version 2.3.2.

The Problem

When a user tries to change the lists they are subscribed to, and they don't check the boxes next to any lists, Newsletter Made Simple will throw the following error:

Warning: Invalid argument supplied for foreach() in/home/cantitoe/public_html/modules/NMS/action.do_usersettings.phpon line 78

The user doesn't need to see that error.

The Solution

Open the file: action.do_usersettings.php

Near line 76 find:

  1. // convert the lists array into a flat array
    
  2. $newlists = array();
    
  3. foreach( $params['lists'] as $newelem )
    
  4. {
    
  5.   $newlists[] = $newelem[0];
    
  6. }

Change it to:

  1. // convert the lists array into a flat array
    
  2. $newlists = array();
    
  3. // added a check here to see if anything was selected
    
  4. if (isset($params['lists'])) {
    
  5.   foreach( $params['lists'] as $newelem ) {
    
  6.     $newlists[] = $newelem[0];
    
  7.   }
    
  8. }


Fix: When importing a CSV file, do not re-add a user to a list, when their email exists in the database.

The Problem

Some of my clients want to use Outlook or some other 3rd party application to manage customers. To update their bulk email lists, they import and export csv files.

If a user has unsubscribe from a list, their email address can inadvertently be put back on the list during a CSV file import. Not good for those of us in the United States; CANSPAM laws again.

What I prefer to do is check for email address that already exist in the newsletter database. If an email address exists in the database I have come up with two acceptable ways of handing the situation:

  1. Method One: All users are already on the lists they want to be on. When an email already exists in the database just skip it and move on to the next email in the CSV.
  2. Method Two: As long as the user is subscribed to at least one email list, they are free game for the new bulk list assignment.

The Solution

Open the file: action.do_import_users.php

Near line 132 find:

  1. $userid = $db->GetOne($query,array($email));

Add after it:

  1. // user exists in database flag
    
  2. $userInDBFlag = ( !$userid ) ? False : True;

Near line 158 find:

  1. // and add him to the list(s)
    
  2. $query = 'INSERT INTO '.NMS_LISTUSER_TABLE."
    (userid,listid,active,
    
  3. entered)
    
  4. 	VALUES (?,?,1,$now)";
    
  5. foreach( $params['input_lists'] as $listid )
    
  6. {
    
  7.   $dbr = $db->Execute($query, array($userid,$listid));
    
  8.   if( $dbr )
    
  9.   {
    
  10.     $membershipsadded++;
    
  11.   }
    
  12. }

Change it to (Method One):

  1. // and add him to the list(s)
    
  2. // METHOD ONE: just ignore all old users already in the DB
    
  3. if( !$userInDBFlag ) {
    
  4.   $query = 'INSERT INTO '.NMS_LISTUSER_TABLE."
    (userid,listid,active,
    
  5. entered)
    
  6. 	VALUES (?,?,1,$now)";
    
  7.   foreach( $params['input_lists'] as $listid )
    
  8.   {
    
  9.     $dbr = $db->Execute($query, array($userid,$listid));
    
  10.     if( $dbr )
    
  11.     {
    
  12.       membershipsadded++;
    
  13.     }
    
  14.   }
    
  15. }


Fix: Unsubscribe in one step

The Problem

The default action for the NMS unsubscribe {$unsubscribe} is a multi-step process. When the user clicks the unsubscribe link in the bulk email it takes them to the website, which then sends them another email with the actual unsubscribe link. This means the user has to open the second email and click the actual un- subscribe link.

The problem with this is that in some cases the user never looks at the second email, thinking it is just a notice about a successful unsubscribe. They then complain that the unsubscribe link doesn't work.

I prefer to make the unsubscribe process a one step process. The following changes make the unsubscribe link {$unsubscribe} go directly to the unsubscribe process.

The Solution

Open the file: action.defaulturl.php

Near line 60 find:

  1. case 'unsub_email':
    
  2. $action = 'unsubscribe_email';

Change it to:

  1. case 'unsub_email':
    
  2. $action = 'unsubscribe';


Fix: Keep link relative when the HREF is a link to an on page anchor

This problem has been fixed in NMS version 2.3.2.

The Problem

The NMS code generates absolute links when it process jobs. This is great for everything in an email, except for, on page anchors. An in this newsletter table of contents is an example use of this. This default behavior changes href="#someAnchor" to something like href="www.yoursite.com/#someAnchor".

The following fix keeps on page anchors as relative so they work when the email is opened by the receiver href="#someAnchor".

The Solution

Open the file: function.utils.php

Near line 144 find:

  1. //Inputs the extracted string into the function make_abs
    
  2. $output_uri = _make_abs($input_uri, $base_url);
    
  3. echo "DEBUG: src1 = $src, input_uri = $input_uri, output_uri = 
    
  4. $output_uri, ";
    
  5. $input_uri = str_replace('?','\?',$input_uri);
    
  6. //Replaces the relative URI with the absolute one
    
  7. $src =
    eregi_replace("((href|src|action)=\")$input_uri(\")",
    
    
  8. "\\1$output_uri\\3", $src);
    
  9. echo "DEBUG: src2 = $src<br /><br />";

Change it to:

  1. //do not turn # anchor links into fully qualified URLs
    
  2. if(!preg_match('/#(.*)/i',$input_uri)) {
    
  3.   //Inputs the extracted string into the function make_abs
    
  4.   $output_uri = _make_abs($input_uri, $base_url);
    
  5.   echo "DEBUG: src1 = $src, input_uri = $input_uri, output_uri = 
    
  6. $output_uri, ";
    
  7.   $input_uri = str_replace('?','\?',$input_uri);
    
  8.   //Replaces the relative URI with the absolute one
    
  9.   $src =
    eregi_replace("((href|src|action)=\")$input_uri(\")",
    
    
  10. "\\1$output_uri\\3", $src);
    
  11.   echo "DEBUG: src2 = $src<br /><br />";
    
  12. }

Share
Like what you read? Get updates for free!
comments powered by Disqus