Unsubscribe page

Hey Guys,

I am trying to setup a email unsubscribe page with maybe a MSSQL preffered database.

Basically there will a link in the email which takes the user to this page, where he can enter his email address and click on the unsubscribe button.

A captcha would be nice as well.

And then that email address is added into a database, which only has those email addresses.

I basically need help with the following:

How can the email address be inserted in the database?
And is there a way to automatically place the email address from the message into the email address tab of the unsubscribe page.?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ok, in the email you use the link:
 if you want to populate other variables then use the "&" sign and define your variables, Example:
Then you use a querystring code to populate the form with their email address. Check this link for how: http://whn.vdhri.net/2005/10/how_to_use_the_query_string_in_php.html
I'm assuming you already know how to program websites with databases. If not, I'm sorry I can't help you there as I don't code php. Anyways I gave you a start.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark BradyPrincipal Data EngineerCommented:
If the user enters the email into a form on the "Unsubscribe" page manually then this will work. Just replace my variables to suit your situation:

<?php  // unsubscribe.php
include("database_connect_script"); // or just put your database connection code here instead
$email = $_POST['email'];

if($email != ""){ // Check for a value in the $email variable
$sql = "SELECT `email` FROM `your_table` WHERE `email` = '$email'";
$result = mysql_query($sql)or die(mysql_error());
$nums = mysql_num_rows($result);  // See if you found the email address

if($nums > 0) {      // we found it!
$remove = "DELETE FROM `your_table` WHERE `email` = '$email'";
$result = mysql_query($remove)or die(mysql_error());
echo "Thanks - ".$email." has been removed from our database.<br>";
echo "Click <a href=\"index.php\">Here</a> to return to the main page...";

    }  // Ok the above code captures the email address entered on the form and if it is found in the      //database, it will remove it. Now for the form...

?> // Stop the PHP engine for some html. You don't have to do this.
<form action="unsubscribe.php" method="POST">
Please enter your email address to be removed <input type="text" name="email" value="">
<input type="submit" value="Unsubscribe">

That's it !

Just something to add here. you may NOT want to delete/remove the email addresses from your database but keep them for future use. I would tend to add a column to the contact table with a switch. 0 for "do NOT contact" or 1 for contact. Then when you do your mailings, add a where clause that only sends mail to those emails that have a 1 but not to anything with a 0.

Hope this makes sense to you....
Mark BradyPrincipal Data EngineerCommented:
I forgot the capcher thing. There are plenty of FREE capcher scripts out there so google "free capcher scripts php"

If you prefer to make your own, you can ask here and we can teach you how. I prefer not to just give away code but instead teach others how to do it for themselves. That way you get to learn. It's up to you though, like I said there are loads of free ones out there.

Let me know which way you would like to go and I'll be happy to help.
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

elvin66 said:
Then when you do your mailings, add a where clause that only sends mail to those emails that have a 1 but not to anything with a 0.  
It would actually be better and more efficient to handle that in your Select statement, this line, (taking a stab here since I don't do php):
$sql = "SELECT `email`, 'contactme' FROM `your_table` WHERE `email` = '$email' and 'contactme' = '1'";
Correct me if I wrote it wrong elvin, it's similar to classic asp but not exact...
Mark BradyPrincipal Data EngineerCommented:
mmarx82:  That is exactly what I m eant by saying "then when you do your mailings.....etc"  I meant that you would put it in a mysql statement as a "WHERE" caluse. By the way, your PHP looks pretty good to me !  Only thing is if you are going to use back tics ` ` around column names then you should do it for any column names in your statement. Not that it won't run if you don't but it confuses some people and they want to know why one column has back tics and the very next one has quotes ' '  This would be better....

$sql = "SELECT `email`, `contactme` FROM `your_table` WHERE `email` = '$email' and `contactme` = '1'";

If the `contactme` column is of type 'Integer' you don't need to quotes around 1.

thanks i know the learning curve from classic asp to php is minimal i just haven't taken the time to do it, but because they are so close I understand what's going on and with examples i know i could get it.
Mark BradyPrincipal Data EngineerCommented:
Have you done much in javascript coding?  Javascript and PHP are almost identical in syntax. Obviously PHP is server side and javascript is client side but they work really well together. You already have the database stuff down so if you added javascript (and possibly ajax) and PHP mixed with good old CSS style sheets and basic HTML you will make killer web pages. I reckon it's worth the effort to learn if you have the time (yawn)
i do some javascript, prob another reason it's easier for me to understand. haven't done any ajax stuff though. they pay me to work full time on their website ;-) which is prob 75% databased. isn't it funny we have to mix all those technologies to come up with the final product. whoever comes up with an easy way to combine all that into one easy to use language ought to make tons of money.
Mark BradyPrincipal Data EngineerCommented:
You got that right!  I just think I have PHP almost mastered and find out to be more efficient I have to learn several other languages. Bugger! I use to write windows programs and I wish I knew how to write a universal language that does everything javascript/ajax/php/html/css does. Ajax is a little tricky but not that hard once you get a hold of it. I'm still learning that one but it is able to run out and contact a php script/page on the server and run it, then get the result and pull it back into your html page all without refreshing the page. Way cool I reckon.
Please assign points or close this. If you need more help please state so or Request Attention on this. Thanks
Mark BradyPrincipal Data EngineerCommented:
Yeah it would be nice to have had at least a comment from the author on our suggestions.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.