SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Divisive Cotton's Avatar
    Join Date
    Jun 2008
    Location
    Andy lives in London, UK
    Posts
    393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Guide to creating a double opt-in email list

    I've been looking for a guide to creating a double opt-in email list.

    You know, somebody signs up, I automatically send them an email asking them to confirm by clicking on the link, they click on the link and then their membership is live.

    I presume this isn't done by cookies as the user may have them switched off in their browser.
    Let everyday be Christmas

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You need 3 elements...

    The form to collect the email address.
    PHP Code:
    #form
    <form action="signUp.php" method="post">
        <
    input type="text" name="email" />
        <
    input type="submit" name="submit" value="submit" />
    </
    form
    A receiving script for the form which uses the email, saves it to a database which you can refer to later, generates a key then fires off an email to the specified address with the key.
    PHP Code:
    #signUp.php
    <?php
    if(true === array_key_exists('submit'$_POST))
    {
        
    $rResult mysql_query(
            
    sprintf(
                
    "INSERT INTO subscribers (email, status)VALUES('%s', 'pending')",
                
    $_POST['email']
            )
        );
        
    mail(
            
    $_POST['email'],
            
    'Subscriber Confirmation',
            
    sprintf(
                
    'Thankyou, please visit http://www.website.com/confirmSignUp.php?key=%s to confirm your subscription.',
                
    sha1($_POST['email'])
            ),
            
    null,
            
    null
        
    );
        echo 
    'Thankyou, please check the provided email for a link to confirm your subscription.';
        exit;
    }
    ?>
    ...and lastly, a script to validate the provided key and update the database.
    PHP Code:
    #confirmSignUp.php
    <?php
    if(true === array_key_exists('key'$_GET))
    {
        
    $rResult mysql_query(
            
    sprintf(
                
    "UPDATE subscribers SET status = 'confirmed' WHERE email = SHA1('%s')",
                
    $_GET['key']
            )
        );
        if(
    mysql_affected_rows() > 0)
        {
            echo 
    'Thankyou, email confirmed';
        }
        else
        {
            echo 
    'Sorry, account unvalidated.';
        }
        exit;
    }
    ?>
    Although very basic and requires some validation / filtering attention, that should get you going.

    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


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
  •