PHPList 2 E/mail Campaign Manager
上QQ阅读APP看书,第一时间看更新

Creating a custom subscribe page

Now that we know how to create a basic subscriber page, we may want to capture more information about our customers when they sign up. In this example, let's assume we'd like to know their name and movie genre preferences.

Creating attributes

While we can take advantage of the built-in attributes, we can also create our own attributes to further personalize our e-mails. Let's create a new, optional attribute for the movie genre preference:

  1. On the main admin page, click on the attributes link:
  2. Click on Add a new one to create a new attribute:
  3. You are hyperlinked to the bottom of the page for the new attribute form. Enter a name for the attribute (Movie Genre) and an attribute type. In this case, checkboxgroup was chosen, because our readers may have more than one genre preference. Unless you want the attribute to be mandatory, remove the check from the checkbox next to Is this attribute required?. Click on Save Changes to create the new attribute:
  4. Once you've saved the changes, your attribute is created, but doesn't yet have any values for selection. To add values for selection, return to the main admin page, and click on the name of your attribute (Movie Genre) under the Configuration functions section:
  5. Click add new to start adding attribute values:
  6. Add the attribute values, one per line, and then click on add new Movie Genre to save:
  7. After saving your values, you can reorder, delete, or add new values from the same page:

Creating subscribe page

Let's create a new subscribe page by clicking on subscribe pages from the right-hand navigation bar and then on the add a new one link at the bottom of the list of subscribe pages:

Customizing title and text

Name the new page Movie Buffs and enter custom intro text:

We can also customize the thank you page and the welcome/confirmation messages, but we'll leave them to the phpList default in this example.

Customizing the HTML header and footer

Make a few minor adjustments to the HTML for the header and footer. In the following example, we will change the table width from 710 to 410 in the header, and add a custom H3 section "Your number #1 source for movie rentals!" to the footer:

Note

These defaults are assigned to a new subscribe page when it is created. To change the defaults for any future subscribe pages, edit them under the configure page.

Customizing delivery options

As we intend to deliver bright and colorful e-mails to our customers, let's set the default e-mail format to HTML, but allow the subscriber to opt for plain text e-mails with a checkbox:

Selecting attributes

Under the attribute selection section, select the Name, Country, and Movie Genre attributes:

Selecting list

Finally, select the list to which this subscribe page will apply and Save and Activate your new list!

View your new custom subscribe page to confirm that it looks as you want it to:

Protecting your subscribe page from spammers

A major problem with online forms is the propensity of automated spam-bots to target them and fill your database or inbox with annoying false subscriptions and messages.

phpList includes a basic built-in level of spam protection, which is enabled by default. (See the USE_SPAM_BLOCK and NOTIFY_SPAM values in config/config.php).

To add an additional layer of spam-protection, we can incorporate reCAPTCHA (http://www.google.com/recaptcha), a free service that both serves to protect online forms from spammers and to help digitize books, newspapers, and so on.

Note

Note that the following example requires changes to the phpList source code, which will be lost when performing an upgrade and the changes will, therefore, need to be reapplied after each successive upgrade.

Signing up for reCAPTCHA keys and downloading the PHP library

The first step in implementing reCAPTCHA is to sign up (for free) to obtain a public / private key combination specific to your domain. Go to http://www.google.com/recaptcha and sign up.

Once you've been given your public and private key, record these somewhere safe and proceed to download the PHP library from http://code.google.com/apis/recaptcha/docs/php.html. As mentioned on the documentation page, you only need the recaptchalib.php from the library—the rest of the files are supplemental.

Extract recaptchalib.php from the downloaded zip file and save it to the admin/ folder of your phpList installation. Be sure to confirm that your web server user has read-access to this file.

Modifying index.php

Edit index.php (in the root of your phpList installation) and search for USE_SPAM_BLOCK. There is a line that reads:

if (USE_SPAM_BLOCK)

Insert the following code above this line:

// Insert reCAPTCHA if library exists and webserver has permission to read it
if (file_exists('admin/recaptchalib.php') && is_readable('admin/recaptchalib.php')) {
require_once('admin/recaptchalib.php');
$publickey = "your_public_key "; // you got this from the signup page
$html .= recaptcha_get_html($publickey);
}

Modifying admin/subscribelib2.php

Edit admin/subscribelib2.php and search for spambot. There is a line that reads:

// anti spambot check

Insert the following code above this line:

// Confirm reCAPTCHA was successfully entered
if (file_exists('admin/recaptchalib.php') && is_readable('admin/recaptchalib.php')) {
require_once('admin/recaptchalib.php');
$privatekey = "your_private_key ";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$missing = 'Please try typing the two words again';
$allthere = 0;
}
}

Tip

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

This will generate a reCAPTCHA input box on your subscribe form, and will return an error if a user tries to subscribe without correctly filling out the reCAPTCHA: