954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Unsubscribe link

I am using a php script for sending email alerts to a list of recipients that I have in MySQL. I want to automate the unsubscribe process for recipients because right now I have a static page where they have to manually enter their info. Since anyways I am calling out the variables in my script for each individual recipient to send emails, I can perhaps also customize the unsubscribe url for each that can have info about their email and keyword that they had initial signed up for. Do you guys think it is possible to auto populate my form fields using this method? Or would you recommend any other method? Here's a brief code

$rr=$row["keyword"];
		$tt=$row["emailid"];
        $to= $tt;
	$subject = 'New updates for '.$rr;
	$message='<html><body><b>Alerts for '.$rr.'</b>';
	$message.='<b>'.$total.' updates found</b>';
	$i=1;
	while ($row= mysql_fetch_array($query))
 	 {
$message.='<span style="font-size:13px"><b>';
$message.=$i.') '.$row["title"].'</b></span>';
 		$message.=' '.$row["link"].'';
 		$i=$i+1;
 	 }
 	$message.='Thanks for setting up alerts ';
	$message.='To unsubscribe from daily alerts, please click the link below,';
	$message.='<a href="http://www.domain.com/alert_unsubcribe.php">Unsubscribe</a>';
	$message.='</body></html>'; 
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
s0bigg
Newbie Poster
23 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

The most basic method would be to attach their email address to the unsubscribe url and then use $_GET at the unsubscribe page to update your database and then just display a page to them to say the have unsubscribe. Briefly:

<a href="http://www.domain.com/alert_unsubcribe.php?email={$tt}">Unsubscribe</a>

Then at the unsubscribe page:

if (isset($_GET['email']) {
mysql_query("UPDATE recipients SET subscribed=0 WHERE email={$_GET['email']} LIMIT 1");

Or delete their details if that is how you have things set up.

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

I agree with simplypixie. I'd go further and include a confirmation hash to go with the email address, e.g.

$conf = hash("sha256", 'saltysaltandmoresalt' . $tt . 'evenmoresalt');

$message.="<a href=\"http://www.domain.com/alert_unsubcribe.php?email={$tt}&conf={$conf}\">Unsubscribe</a>";


That should avoid malicious 3rd party unsubscribers.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Thanks Ardav and simplypixie, I will try it out. I am using both email and keyword combination to unsubscribe. How can I integrate that into the link? Can you guys please help me with the php syntax on unsubscribe page. I appreciate your help..

<a href="http://www.domain.com/alert_unsubcribe.php?email={$tt}&keyword={$rr}">Unsubscribe</a>
s0bigg
Newbie Poster
23 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

just like ardav said you can just encrypt your keyword in your case $rr

$keyword = hash("sha256", 'saltysaltandmoresalt' . $rr . 'evenmoresalt');

echo "<a href=\"http://www.domain.com/alert_unsubcribe.php?email=".$tt."&keyword=".$keyword."\">Unsubscribe</a>";
HITMANOF44th
Posting Whiz in Training
283 posts since Apr 2009
Reputation Points: 24
Solved Threads: 33
 

I made it work with a simple unsubscribe link.. but I am having a weird problem now. The keyword that I want pull up on the webpage is only showing the first word and skips all following words. Email is coming up fine. Why would this happen?

s0bigg
Newbie Poster
23 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

Can you give an example of what SHOULD display and what's ACTUALLY showing?

You may have to go 'Use Advanced Editor' and uncheck 'Automatically parse links in text' under Miscellaneous Options to display the urls.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: