Results 1 to 4 of 4

Thread: Opt Out PHP Code

  1. #1
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Opt Out PHP Code

    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?

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

  3. #3
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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
    HTML Code:
    <a href="http://www.example.com/unsubscribe.php?email=useremail@example.com">Click to Unsubscribe</a>
    and your unsubscribe.php to
    PHP Code:
    <?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.
    Last edited by traq; 11-29-2011 at 08:46 PM.

  5. The Following User Says Thank You to traq For This Useful Post:

    djr33 (11-29-2011)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •