Log in

View Full Version : Opt Out PHP Code



maryclare
11-29-2011, 08:03 PM
Hello All,

I am new here. I am trying to include a link in an email I send out giving the recepients the ability to opt out of the distribution list.

From what I have read, I have created a file on the server called mysite.com/unsubscribe.php.
The unsubscribe.php file contains:

<?php

mail("mary@mydomain.com","unsubscribe", $_POST['email']);
?>

When someone clicks on the link from an email, I get the unsubscribe email from the server, but it does not contain the email address it is coming from.

Any suggestions?

traq
11-29-2011, 08:16 PM
what does your form look like?

maryclare
11-29-2011, 08:24 PM
I am not using a form. I am sending emails with text that says

To Unsubscribe from this mailing list, Click here

www.mysite.com/unsubscribe

traq
11-29-2011, 08:39 PM
in that case, $_POST['email'] is blank because you are not submitting any info via POST.

a URL (like in your hyperlink) is submitted via GET. You could change your link to
<a href="http://www.example.com/unsubscribe.php?email=useremail@example.com">Click to Unsubscribe</a> and your unsubscribe.php to
<?php
mail("mary@mydomain.com","unsubscribe", $_GET['email']);you'd probably want to add some measure of validation to that, though. at least check to make sure there is an email address to submit (so you don't get blank emails), and probably a check to see if the email is subscribed (so you can say "you're already unsubscribed" when an email is submitted that's not on your mailing list).

You should also be aware that a page like this will not meet legal guidelines (in the US) if you're sending out bulk emails. You need to keep an "opt-out" list, not simply remove people from your mailing list. read more here (http://business.ftc.gov/documents/bus61-can-spam-act-compliance-guide-business).