Simple One Click Unsubscribe

In this post I will try to explain how to create a simple one click unsubscribe system for your emails.This post goes with another post that I am writing called “create your own auto-responder” but I feel that this is useful even to people not building the auto-responder so I made it is’s own post. It is very simple and as long as you have access to the database storing the emails that you are collecting you can do this.

When working with mailing lists and sending email it is very important to allow people to unsubscribe to your list. In the USA (where I am), we all have to follow the Federal Trade Commissions “CAN-SPAM Act” which gives us a small list of rules that we need to follow and adding a clear way to unsubscribe is on it. For anyone not in the US there is probably a similar set of guidelines you must follow.

I have seen a lot of different ways to unsubscribe in the emails that I get (as I’m sure you have) and I feel that the 1 click way is the way that it should be, it looks the most professional and “above board”. A user should be able to click the link and be done with it, no tedious process, no explanation, and no guilt trip.

What will we do?

We will put a dynamic link in the emails that we send out, when a user clicks that link it will open a .php file that will update our database to mark that user as unsubscribed. I would like to say that I feel that deleting the user from our database outright is a better option, and is what the user expects us to do when they click unsubscribe. It would be very easy, safer, and even a little less work to delete the user rather than update their status. I chose to update their status because when you delete a user you will also lose some important information (such as how many emails they opened, how many they didn’t, if they clicked links, etc) before you get a chance to look the data over and possibly learn things that can improve your service.

The first thing that we will need to do is create the .php file called unsubscribe.php

It looks like this: (get the code here: Unsubscribe file)

require 'database.php'; //connection to database PDO

$step=1;
$subscribe = 1;
$email = $_GET["email"];

if ($step ==1)
{// change to your table name
$sql = "UPDATE tablename SET subscribe = :subscribe
WHERE email = :email";
$stmt = $db->prepare($sql);

$stmt->bindParam(':subscribe', $subscribe, PDO::PARAM_INT);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);

$stmt->execute();
echo "You are now unsubscribed";
}

That file will unsubscribe you! It sets the “subscribe” field in our database to 1. When we send emails we must filter out all of the addresses that have that field set to 1.

Now all we have to do is put a link to that file in our emails using _GET and including the users email in the link and it will look like this.

http://yourdomain.com/unsubscribe.php?email=$email

That’s all there is to it. When the email is being sent the php that is sending it will have access to the $email variable. The email in the link will be the same as the email that you are sending to, and when clicked unsubscribe.php will update the users status to unsubscribed.

As you can see it was pretty simple to implement.

I would be glad to do this for you at a very reasonable rate, please message me at ed@32hertz.com


Go back to Main Blog

twittertwitter
twittertwitter