Jump to content

email- generated id in the email title


prichardson

Recommended Posts

I was wondering if anyone new any links for javascript code for creating an random id on the email title.Or if it is easy to do for someone who could help me on the coding of the creating an random id on the email title?Bascially someone to send an email to us- and i would like to make the email title that would be sent to us to have an id number inserted in the email title box.

Link to comment
Share on other sites

If you want to generate a random number using Javascript, you can use the Math.rand method. You should be able to find documentation for it online. If you are using mailto to send email, a better alternative would be to use a server-side language such as PHP to generate your data so that the user cannot change it and use the server to send the email, instead of relying on the user having a mail client installed and configured on their computer to send the email. Not everyone has that, and even if they do they can change or delete whatever you put in the email. If you need any accountability or verification in this sytem you will not want to use mailto, you will want the server to post the information in a database or send an email.

Link to comment
Share on other sites

If you want the IDs generated to be unique you will need some server-side scripting to store the used IDs. I haven even touched PHP yet, or any other server side language yet so I may not be in a position to give good advice here... But if you were to use a sequential ID system, then encode the number so it appears random, you will only have to store one number->The last ID created. Just a thought really.

Link to comment
Share on other sites

For a reasonably unique ID, you can also use the SHA-1 algorithm to create a 40-character string. You can base the string off of something like the user's IP address and the current time. This would ensure that one user submitting at two different times would get different IDs, and also two users submitting at exactly the same time would also get different IDs. To generate an ID like that, you would use something like this in PHP:$id = sha1($_SERVER['REMOTE_ADDR'] . time());You can even put that in a loop checking for duplicates, so if the ID is already in the database you can generate another one and since you are using the timestamp the second ID will be different then the first. That would look something like this:

$id = sha1($_SERVER['REMOTE_ADDR'] . microtime());$db_check = mysql_query("SELECT id FROM database_table WHERE id={$id}");while (mysql_num_rows($db_check) > 0){  // generate another ID  $id = sha1($_SERVER['REMOTE_ADDR'] . microtime());  // check again  $db_check = mysql_query("SELECT id FROM database_table WHERE id={$id}");}// at this point in the code you know that $id is a unique ID not already in the database

As far as sending email with PHP goes, you can check this reference page to see plenty of examples using the mail function:http://www.php.net/manual/en/function.mail.php

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...