Unsubscribe e-mails problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lxm
Forum Newbie
Posts: 4
Joined: Tue Apr 29, 2008 4:10 am

Unsubscribe e-mails problem!

Post by lxm »

Hi all,

I want to create an 'Unsubscribe' link in the e-mails I'm sending out. If the person receiving the e-mail no longer wants to receive e-mails from me, they click the 'Unsubscribe' link in the e-mail which will be something like this:

http://www.mysite.com/unsub.php?email=user@msn.com

So upon click this link they will be taken to a page that says, do you wish to stop receiving these e-mails - Yes / No?

When the user clicks 'Yes', I need to save the e-mail address from the link in a text file.
At the moment I'm using the following php code on the page that the link takes the user to:

Code: Select all

 
 
 
<?php
 
$email = $_GET["email"];
$conn = fopen("emails.txt","a") or exit("Error In Opening The File!!");
fwrite($conn,$email."\n");
fclose($conn)
 
?> 
 
 
At the moment this code saves the email address to a text file as soon as the page is opened, however, I need it to save the email address when the user clicks 'Yes' instead.

The best way I can think of doing this is by making the link take the user to a page saying 'Unsubscribe? Yes / No' then when they click yes they are taken to another page which then has the code in above and saves the e-mail address when the page is opened.

My problem is, I don't know how to carry the e-mail address in the URL from one page to the next, can anyone help?


Thanks,

Laura
hansford
Forum Commoner
Posts: 91
Joined: Mon May 26, 2008 12:38 am

Re: Unsubscribe e-mails problem!

Post by hansford »

you send the user to a page like this where they will be asked if they want to unsubscribe. they have 2 buttons-a'yes' and a 'no'.
when they click either button the form is submitted back to this same page where php will check to see if one of the buttons has been clicked. the form action='' " will point to this page.


<html>
<body>

<?php
if(isset($_POST['action'])){

if($_POST['action'] == 'yes'){

echo 'place your code here';
}
elseif($_POST['action'] == 'no'){

echo echo 'place your code here';
}
}
else{

echo "<form name='unsubscribe' method='post' action='unsubscribe.php'>";
echo "do you wish to unsubscribe?<input type='submit' name='action' value='yes'/>";
echo "<input type='submit' name='action' value='no'/></form>";
}

?>
</html>
</body>
Post Reply