Both php and MySQL support MD5().  Consider this:

 // Define a secret key
$secret_key = "ThisIsASecretKey123";

 // Take the user's current email address
$email_address = "[EMAIL PROTECTED]";

 // And create a unique ID
$unique_id = md5($email_address.$secret_key);

Stick this unique id in the email you send to you user.$unique_id

Then when someone sends back the $unique_id by clicking on your link, you
can instuct MySQL to disable the record:

"UPDATE users SET send_email = 'NO' WHERE
MD5(email_address.'ThisIsASecretKey123')=$unique_id "

The $secret_key prevents someone from guessing an email address, MD5 them,
and sending it to you script.  They would also need to know the secret key
to guess correctly.  This way you also do not need to "store" the hash
anywhere.  You could also update the secret key from time to time for

What do you think?

Robert V. Zwink

-----Original Message-----
From: Ashley M. Kirchner [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 22, 2002 12:38 PM
To: PHP-General List
Subject: [PHP] Maillist

    I need to send out several hundred, to several thousand emails out of
database.  Now, before everyone starts telling me to use an actual MLM for
this, let me explain what I need to do.

    I need to send a unique ID with each message, in the form of a URL.  We
want to make unsubscribing as easy as possible for our clients, so what I
on doing is sending out a URL in the body of the message that contains a
ID.  When they click on that URL, it hits another script on our website
than takes that ID, searches for it in the database and flags that record
returns a 'Thank you' page.)

    So, somehow, I need to generate a unique ID for each message send, stick
that ID into the database with the corresponding email address that it was
sent to and then....wait.

    What's the best way to approach this? Should I generate IDs outside of
script, and then query the database for both the email and the ID and
the message that way?  Or should I dynamically generate an ID during the
mailing process and shove it in the DB as the message goes out?

    Suggestions, criticism, comments...welcome.

W | I haven't lost my mind; it's backed up on tape somewhere.
  Ashley M. Kirchner <mailto:[EMAIL PROTECTED]>   .   303.442.6410 x130
  IT Director / SysAdmin / WebSmith             .     800.441.3873 x130
  Photo Craft Laboratories, Inc.            .     3550 Arapahoe Ave. #6 ..... .  .    .       Boulder, CO 80303, U.S.A.

PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to