Chapter 13: Getting Subscribers

Google

How about showing the visitors a thank-you page after they've subscribed? No problem. Assign the URL of the thank-you page to a variable and use the header() function to display that page. An external script could be written like this:

<?php
$file = "/cgi-bin/subscribers.txt";
$thanks = "http://www.mydomain.com/thankyou.php";
$browser = getenv("HTTP_USER_AGENT")
$date = date("Y-m-d h:i:s");
$ip = getenv("REMOTE_ADDR");
$url = getenv("HTTP_REFERER");
$browser = getenv("HTTP_USER_AGENT");
$handle = fopen($file, "a");
$line = "$date|$email|$ip|$url|$browser|$likePHP\n";
fwrite($handle, $line) or die("Couldn't write to file");
fclose($handle);
$to = "subscribe@mylisthost.com";
$subject = "subscribe";
$body = "subscribe";
$headers = "Content-Type: text/plain; charset=us/ascii\nFrom:
$name <$email>\nReply-To: <$email>\nReturn-Path: <$email>\nX-Mailer: PHP";
if ($to != "") {mail($to,$subject,$body,$headers);}
header("Location: $thanks");
die();
?>

But - if it's on the same page and will be called again, it's not allowed to send a new set of headers! That would happen if you used the header() function and it would bomb. One solution is to put the contents of the thankyou page into a small file that has no header information and include() that file in your page.

Here's an example:

<table width="600" border="0"
align="center" bordercolor="#000000" bgcolor="#FFFFFF" cellpadding=10>
<tr>
  <td bordercolor="#FFFFFF" bgcolor="#FFFFFF">
  <p><font color="#CC0000" size=7 face=Arial, Helvetica, sans-serif>Thank you
  for your subscribing to our newsletter!</font></p>
  <p><font color="#000000" size="3" face="Arial, Helvetica, sans-serif"><strong>Your
  first issue has been sent to you at the email address you gave us.</strong></font>
  </td>
</tr>
</table>

You could save this HTML code in a file called ty.html. You'd also have to have some logic that would prevent the rest of the page from being shown when you didn't want it to be seen. What you're doing is letting the code decide what content to show on the page. Your PHP script for displaying the page would then look something like this:

<?php
include("header.html");
$form = "Put the HTML for the form here...";
// put some code here to determine whether to show the thankyou page
if($show_ty_page == "Yes") {
  include("ty.html");
}
else { include("other_content.html"); }
include("footer.html");
?>

Tracking subscribers

To continue the theme of automated subscriptions and PHP, here's a thought: Your script can capture the domain from which the request came and log that in your database. Many other types of data can be captured with or without asking the new subscriber to supply it. Refer to chapter 10 for more details. The techniques I showed you there will work for this type of tracking, too.

It's also quite simple to determine which ad brought in a new subscriber. You "encode" the email address and check the code when they join. This is often suggested as a manual operation but it can be scripted. An email address link can have a query string including the subject and/or body of a message.

Counting the number of subscriptions that came in with a specific character string shows you how effective the ad was. Comparing your number of new subscribers to the number of people on the newsletter list gives you a rough estimate of how responsive the list was.

Be aware that an ezine list that claims to have 10,000 members may not not have 10,000 people actually reading the ezine. Some emails are deleted by over-zealous spam filters. Some people don't read all their email. You get the picture.

Why not script the process and log the responses to several different ads? That way you can test and refine the ads until they get the best response possible. Once you've determined which ads work, use them over and over. Continue to monitor their response rates in case the rates change. Save money by only paying to run ads that you already know will produce good results.


Dealing with spammers: advanced filtering

Ours is not a perfect world. People are going to do things that will annoy you. One such irritation is spamming. If you can identify certain domains where a high percentage of spam originates, why not block all email addresses in that domain? I do. I compare the email addresses that people supply to a list of domains that are mostly trouble. If an address matches one of these, the person is told that the email address is "not allowed" or "unacceptable."

PHP's string-comparison functions make this a piece of cake! See Appendix C for a function called "verify_email" that will reject a lot of "bad" email addresses. Once you look at it, it will be easy to see how you can add more domains to block. Drop this bit of code into a script that is handling subscriptions and the addresses of millions of spammers and autoresponders are denied access to your list.

I developed part of this code by searching for autoresponders in a search engine and looking at how the addresses were constructed. In most cases, all of the addresses were in the domain of the provider. For example, an address in the domain "getresponse.com" is nearly always an autoresponder.

Previous Page   Table of Contents   Next Page

Copyright © 2004 Steve Humphrey