Newsletter Plugin - Subscriber's name and any other field?

8 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 14, 2013   (RSS)

Is there a hook in the process to allow the use of more than just an email address?  Most of my clients that use another open-source list manager almost always request first and last names so they can personalize the newsletter going out.  Some of them also request the ability to have other fields in the register form such as birth month/day, anniversary month/day, etc. so they can send messages to these people on these special days.

Does the newsletter system offer any of these capabilities?

Thanks,

Gary.

Hi Gary,

Unfortunately, there isn't currently a way you can only send the news letter to users on specific days or define which users receive the newsletter.

But I have come up with a workaround for adding subscriber related placeholders to the newsletter. If you open up the newsLetterBuilder.php file, which you should find in your plugins directory. Around line 913 you should see the function nlb_placeholders, I've added a new line that will load the user fields from the subscribers section into the placeholders:

function nlb_placeholders($to_email = '', $messageNum = '0', $subscriber = array()) {
  $placeholders = array();

  //Set users based variables to a placeholders first.
  $placeholders = mysql_get('_nlb_subscribers', null, "email = '$to_email'");

  // load/cache newsletter settings
  static $newsletterSettings;
  if (!isset($newsletterSettings)) { $newsletterSettings  = mysql_get('_nlb_settings', 1); }

  // define shortcut vars
  $subscriberNum     = @$subscriber['num'] ? $subscriber['num']     : '0';
  $subscriberAuthkey = @$subscriber['num'] ? $subscriber['authkey'] : '0';

  // define placeholders - values defined lower in the list can use placeholder defined above them in the list
  // internal placeholders (undocumented)
  $placeholders['message_num']     = $messageNum;
  $placeholders['subscriber_num']  = @$subscriber['num'];
  $placeholders['manage_url']      = $newsletterSettings['manage_url'];

  // public placeholders - values defined lower in the list can use placeholder defined above them in the list
  $placeholders['email_header']    = ''; // placeholder removed in v2.03 - remove the placeholder if it's left in old newsletter content
  $placeholders['email_footer']    = ''; // placeholder removed in v2.03 - remove the placeholder if it's left in old newsletter content
  $placeholders['hostname']        = @$_SERVER['HTTP_HOST'];
  $placeholders['from_name']       = $newsletterSettings['from_name'];
  $placeholders['from_email']      = $newsletterSettings['from_email'];
  $placeholders['to_email']        = $to_email;
  $placeholders['archive_url']     = $newsletterSettings['archive_url'];
  $placeholders['confirm_url']     = $newsletterSettings['manage_url'] . "?n=$subscriberNum&a=$subscriberAuthkey";
  $placeholders['unsubscribe_url'] = $newsletterSettings['manage_url'] . "?n=$subscriberNum&a=$subscriberAuthkey&m=$messageNum&u=1"; // if usernum(n) isn't specified user will just get a debug error message

  // make archive_url trackable
  if ($GLOBALS['NLB_TRACK_LINKS'] && $to_email) { // don't encode for viewer pages
    $encodedLink = urlencode(_nlb_htmlspecialchars_decode($placeholders['archive_url']));
    $placeholders['archive_url'] = $newsletterSettings['manage_url'] . "?l=$encodedLink&m=$messageNum&n=$subscriberNum";
  }

  //
  return $placeholders;
}

So if you added a field called age to the subscribers section. You could add this field to the newsletter by adding #age# where you wanted the age to appear.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Sorry I didn't reply sooner.  I've been out of the office quite a bit this week.

Thank you for the great information.  I will take a look at it.

Gary.

By gversion - April 15, 2013

Hi Greg,

This modification is great! Is it going to be featured by default in future releases of the Newsletter plugin?

Thanks,

Greg

Hi Greg,

I've added the change to our newsletter plugin codebase, this feature will definitely be present in the next release.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gversion - May 7, 2013

Hi Greg,

Could you please explain how I can collect the user's "first name" in the newsletter subscription form?

I have tried the following to collect the first name but it doesn't work, only the email is collected:

                                <form method="post" action="#">
                                    <input type="hidden" name="submitForm" value="1" />
                                    <input type="text" name="first_name" value="<?php echo htmlencode(@$_REQUEST['first_name']) ?>" size="30"/>
                                    <input type="text" name="e" value="<?php echo htmlencode(@$_REQUEST['e']) ?>" size="30"/>
                                    <input type="submit" name="subscribe" value="Subscribe" />
                                </form>

The PHP code in the HEAD is as follows:

<?php
  // error checking
  if (!@$GLOBALS['NEWSLETTER_BUILDER_PLUGIN']) { die("You must activate the newsletter plugin to see this page."); }

  // load newsletter settings
  $newsletterSettings  = mysql_get('_nlb_settings', 1);

  // dispatch form actions
  list($errorsAndAlerts, $isConfirmSubscribe, $isConfirmUnsubscribe) = nlb_manage_dispatch();


?>

I'd be very grateful for any help you can provide.

Thank you,

Greg

By gversion - May 14, 2013

Hi Greg,

Thanks so much for your help with this. It seems there was more thought required than I expected!

I will let you know if I run into any problems.

Regards,

Greg