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.
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:
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:
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.
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:
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:
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:
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.
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.
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); }
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; } }
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:
18.216.55.20