Hello Everyone,

Hope you're having a great weekend, especially in the Chicago land area where it's usually pretty chilly this time of the year and instead it's in the mid eighties.

I'm looking to make an unsubscribe page. I don't know if everything can be done automatically or not and I'm sure it will probably involve MySQL, so that is why I am writing.

Here's the steps I'd like to have happen:

  1. Users hit unsubscribe link in HTML email
  2. Users either enter email in text field on page or simply hit submit button under a text field prefilled with their email address
  3. Users emali is deleted from list

Not looking for "hand out". I don't want a fish: I want to learn how to fish. If I could led in the right direction to accomplish these tasks or a code snippet jump start that would be appreciated. Thanks for your time.

Recommended Answers

All 5 Replies

Member Avatar

Hello Reliable, what you are trying to do is very simple !

When you go to you page, http://www.example.com/unsubcribe.html, you have a form with a text box and a button like this:

<form action="unsubscribe.php" method="post">
    <input name="mail" type="text" size="50" />
    <input name="Submit" type="submit" value="Unsubscribe" />

In your unsubscribe.php, you $_POST mail and validate that is a valid mail and is not empty, then you do this, assume that your database call subscribers and a table call mails that has one column, mail . With unsubscribe.php you verify that is in the database (the mail) and delete it like this:

$mail = $_POST['mail'];
$link = mysql_connect("localhost","root","123456");
$query = mysql_query("SELECT * FROM mails WHERE mail='$mail'");
if(mysql_num_rows($query) == 1){
    mysql_query("DELETE FROM mails WHERE mail='$mail'");
    echo "You are not more subscribe !";
    echo "<meta http-equiv='refresh' content='3;url=index.php'>";
    echo "The mail you entered does not exists or has already been deleted !";
    echo "<meta http-equiv='refresh' content='3;url=index.php'>";
commented: A junior poster on his way up in the ranks +4

That's good stuff. Thank you for your time. You are being a great help. Can't tell you how long I've been searching the internet for the solution. Maybe I was just searching in the wrong places. lol One more thing, though. How do I make it so that the person's email address is already in the box when they get there so that all they have to do is press the unsubscribe button?

Member Avatar

For that you have to read the table with his/her information. You can recibe that info from a $_GET variable or from a post. Suppouse that wi recibe a $_GET (http://www.exmaple.com/unsubscribe.php?mail=mail@mail.com). Then echo the mail on the value input like this

<form action="unsubscribe.php" method="post">
    <input name="mail" type="text" size="50" value="<? echo $_GET['mail']; ?>" />
    <input name="Submit" type="submit" value="Unsubscribe" />

You'll see that the mail is on the text box without writing it your self...

Thank you Thank you Thank you. Haven't tried it yet, but I believe it's going to work. I'll come back in a couple of hours probably to mark this as solved so you can get your credit.

Member Avatar


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.