Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6697185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:25:48+00:00 2026-05-26T06:25:48+00:00

I am trying to write a small PHP script for managing subscriptions for a

  • 0

I am trying to write a small PHP script for managing subscriptions for a mailing list. I was trying to find whatever resources I can find over the internet but I only came up with:

  1. Very simple PHP scripts with only single opt-in or “fake” dual opt-in features.
  2. Very complicated multi MB PHP projects, like PHPList (7.8 MB!)

With “fake” dual opt-in I call methods which either put the email address as the validation string, or what uses cookies in the browser.

All I would like to achieve is:

  1. Someone can write it’s email address in a PHP form and click submit
  2. He receives an email with an URL where he needs to click. The link should not contain the email address but some md5 or random string
  3. Once clicked on the URL he gets to a page which shows “email confirmed”

On the server-end the addresses could be save in a text file in a protected folder or if you believe it’s really important to keep them in a database then in a database.

My questions so far are:

  1. Could someone guide me to some tutorial or write-up about how to write such a script
  2. Whether I should use database or a simple file. All I would need is to insert simple lines of new emails with the possibility of duplicate checking.
  3. How to store the temporary id-s for the double opt-in system. I thought about using something like md5 ("email" . "passphrase") for the id generation and storing them next to the email addresses.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:25:49+00:00Added an answer on May 26, 2026 at 6:25 am

    Just for the fun of it, here is a pretty indepth example. It should be easy to grasp what’s going on in there and why.

    Caveat: Code hasn’t been tested so syntax and other errors are possible.

    <?php
    
    // Salt for hashing confirmation keys
    $salt = 'yoursecretstring12#11;.-_.21';
    
    $url = 'http://www.yoursite.tld/thisscript.php';
    $fromEmail = 'you@yoursite.tld';
    
    $dbHost = 'localhost';
    $dbUser = 'dbuser';
    $dbPass = 'dbpass';
    $dbDatabase = 'dbname';
    
    mysql_connect($dbHost, $dbUser, $dbPass);
    mysql_select_db($dbDatabase);
    
    $ip = $_SERVER["REMOTE_ADDR"];
    
    if ( isset( $_GET['key'] ) && isset( $_GET['email'] ) ) {
    
      // If we have 'email' and 'key' parameters, we are handling an opt-in click
    
      $email = mysql_real_escape_string( $_GET['email'] );
    
      // Check if key matches hash of email and salt combination and if email is really an email
    
      if ( sha1( $email.$salt ) == $_GET['key'] && filter_var($email, FILTER_VALIDATE_EMAIL) ) {
    
        // Check if entry already exists
    
        $checkDupes = mysql_query( "SELECT COUNT(*) as cnt FROM emails WHERE email = '$email'"; ); 
        $result = mysql_fetch_assoc($checkDupes);
    
        if ($result['cnt'] < 1) {
    
          // Fresh email, insert into db along with remote ip and timestamp
    
          mysql_query( "INSERT INTO emails (email, ip, timestamp) VALUES ( '$email', $ip, NOW() );" );
          die('Subscription confirmed!');
    
        } else {
    
          die('Email already exists in database');
    
        }
    
      } else {
    
        die('Key mismatch or invalid email!');  
    
      } 
    
    } else if ( isset( $_POST['email'] ) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
    
      // Form submission, send confirmation email    
    
      $email = $_POST['email'];
      $key = sha1( $email.$salt );
    
      $link = $url . '?email=' . $email . '&key=' . $key;
    
      $mailSubject = 'Please confirm your subscription';
      $mailTo = $email;
      $mailBody = 'Please confirm your subscription by clicking <a href="$link">this link</a>'; 
      $headers = 'From: ' . $fromEmail . "\r\n";
    
      mail( $mailTo, $mailSubject, $mailBody );
    
    } else {
    
      // Present form and show error if needed
    
      if ( isset( $_POST['email'] ) ) {
        echo "Ivalid email submitted!<br />";
      } 
    
      echo '
      <form method="post" action="'.$url.'">
        Email: <input type="text" name="email" /><br />
        <input type="submit" value="Submit" />
      </form>
      ';
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a small script to change the current directory to my
I am trying to write a small php function to take an image and
I am trying to write a small php application and i am facing a
I'm trying to write a small script which parses and executes Brainfuck code, to
How can I run a function on checkbox change? I'm trying to write small
I'm trying to write a small method to loop through and find a GridView
I am trying to use php. I wrote a small script as instructed in
I am trying to write a small PHP function that would go through a
I have been trying to write a script where I can post data to
Begginer's question. I'm trying to write small piece of code in Visual Studio (VB.net)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.