Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts

    coding an UNSUBSCRIBE link

    all,

    i do bulk mailings every once in a while, and I cannot, for the life of me figure out how to give the recipients an unsubscribe link at the bottom. from my research so far, I understand that something like this would work:
    PHP Code:
    <a href='http://www.mydomain.com/unsubscribe.php?email=$array[$i]'>UNSUBSCRIBE HERE</a
    the problem with this process is two fold:

    1) in dreamweaver, the code above is not recognized. as in, the href() attribute and anchor tag shows up as TEXT in the email.

    2) i have absolutely no idea how to go about passing the email value to the PHP script on the unsubscribe page.

    my bulk emails go out through a process of looping through a local database table and submitting a form on a PHP page that includes the mail() function that sends the message. i am totally unfamiliar with the following portion/process of a PHP script that runs based on IDs, identifiers, or so called "criteria":
    PHP Code:
    .php?identifier=MYVALUE 
    I see this type of thing going on all over the internet on most websites and I simply don't get how the programmers are using it to their advantage. If I could get s short explanation from someone here on that process and how to use it, that would be wonderful...

    I would also greatly appreciate it if someone could point me in the right direction of how to "capture" the email address or an accompanying identifier that I can use to unsubscribe them if they click on the universal link I want to include in my email campaigns.

    If any part of this post doesn't make sense, just let me know. I really need to learn this process so I can make my internet programming work more effecient. Thanks all!

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Things after the ? in a URL are called the query string. In PHP you can access those variables by doing something like: $myEmail = $_GET['email'];

    The reason the first block of code you posted does not work is because that's HTML (I'm assuming you're in html at this point in the script) - not php. You need to put the $array[$i] in php tags so that it gets printed. Something like:

    PHP Code:
     <a href='http://www.mydomain.com/unsubscribe.php?email=<?php echo $array[$i]; ?>'>UNSUBSCRIBE HERE</a>
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #3
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    Note that query strings have the format:

    PHP Code:
    .php?first=someValue&second=someValue&third=someValue 
    That is to say, the first variable is preceded by a question mark (?) and subsequent values are preceded by an ampersand (&).

    You could access those values above like so:

    PHP Code:
    $var1 $_GET['first'];
    $var2 $_GET['second'];
    $var3 $_GET['third']; 
    So, if you created a link that was something like

    Code:
    http://www.mydomain.com/unsubscribe.php?email=test@test.com
    You could write a php script like so

    PHP Code:
    <?php

    // Assuming you connect to your database here

    // Just makes it more readable to use the email address in your code...also gives you a copy to modify so the value in the $_GET superglobal remains the same.
    $email $_GET['email'];

    // Be sure to include some sort of security here. Any user could manually change the page URL to, say, drop your entire email table. 

    // Unsubscribe
    $sql "delete from tbl_emails where email = '$email'";
    mysql_query($sql) or die(mysql_error());

    ?>

  • #4
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    thanks guys.

    i have a couple more ?'s here...

    1) i don't have a mySQL database that i can connect to. i have no online database. i send out my email campaigns through my local file, an access database. i run a VBA script through that program that send messages out, one by one. the PHP script knows what the email is by pulling it from one textbox that is on the page...called "email". i put the email from the access db in the box with VBA code. i submit the form on the PHP page by VBA code also. thus, i think my problem lies in the way i'm sending out mail. but i'm a beginner here see, and i don't think i'm prepped with enough knowledge to send out mass emails another way.

    and at any rate, if i were to use the technique mentioned in bacter's post, how in the world do you connect to a single access database on a local machine from PHP? common sense tells me NO, NO WAY. if that were possible, i could just as easily see what's on the presidents agenda for tomorrow by reading his directories on his network computer at the white house!

  • #5
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    I have zero experience with access database and PHP integration, but this might work:

    http://www.w3schools.com/PHP/php_db_odbc.asp

    Someone else will have to confirm my thoughts, though. In any case, that's a terrible way to do a mailing list . Your other options are to

    1. set up a local mail server yourself, install mysql, then use PHP and a new mysql database to send your mail
    2. pay for web hosting and put all your scripts on there
    3. there are also plenty of online services that do this sort of thing...but they like to put their brand on the emails

    There may be more - I'm not an expert on mailing lists.

  • Users who have thanked bacterozoid for this post:

    ajetrumpet (09-01-2009)

  • #6
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by bacterozoid View Post
    I have zero experience with access database and PHP integration, but this might work:

    http://www.w3schools.com/PHP/php_db_odbc.asp

    Someone else will have to confirm my thoughts, though. In any case, that's a terrible way to do a mailing list . Your other options are to

    1. set up a local mail server yourself, install mysql, then use PHP and a new mysql database to send your mail
    2. pay for web hosting and put all your scripts on there - i don't like to pay for things i can do myself
    3. there are also plenty of online services that do this sort of thing...but they like to put their brand on the emails - i used iContact once and I'll never do it again. it's a waste of good money.

    There may be more - I'm not an expert on mailing lists.
    Question about MySQL...where do i get? is it free to install? i know zero about that platform. never worked with it, but i assume it's an online database tool similar to oracle? what are its primary advantages? can you list me a few?

    MS Access is OK, and i started my programming career learning VB and its flavors, but it's boring as he**, and i'm not a fan of bill gates at all. i was when he made cool stuff in BASIC and QDOS, but since he dummed programming down so that the public could do it, it's just not the same, ya know?

  • #7
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    You can get mysql here. It's free to install. If you're new to it, I would recommend a package like AppServ or XAMPP.

    I've always used AppServ on Windows and it's worked fine. It gives you PHP, MySQL (with PHP myAdmin), and Apache.

    MySQL is free and easy to use. Syntax is very similar to Oracle or MS SQL. If you've learned one database, you've learned them all, basically. I don't know what all the differences are, though. I just like MySQL .

    I would get away from MS stuff ASAP. If you like it, that's fine, but PHP/Apache/MySQL is free, easy to use, and highly supported.

  • #8
    Regular Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    169
    Thanks
    26
    Thanked 3 Times in 3 Posts
    The one thing I would add to Bacterozoid's post is to limit the number of deletions to 1. This keeps the user from figuring out a clever way to defeat your code. Also, you want to sanitize your inputs before you use them in a MySQL DB.

    PHP Code:
    <?php
    // sanitize the input
    $_GET['email'] = mysql_real_escape_string($_GET['email']);

    // Unsubscribe
    $sql "delete from tbl_emails where email = '$_GET[\'email\']' LIMIT 1";
    mysql_query($sql) or die(mysql_error());

    ?>

  • #9
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by wldrumstcs View Post
    The one thing I would add to Bacterozoid's post is to limit the number of deletions to 1. This keeps the user from figuring out a clever way to defeat your code. Also, you want to sanitize your inputs before you use them in a MySQL DB.

    PHP Code:
    <?php
    // sanitize the input
    $_GET['email'] = mysql_real_escape_string($_GET['email']);

    // Unsubscribe
    $sql "delete from tbl_emails where email = '$_GET[\'email\']' LIMIT 1";
    mysql_query($sql) or die(mysql_error());

    ?>
    i assume i will learn what this little PHP snippet does once i get going with a mySQL database?


  •  

    Posting Permissions

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