Forum Moderators: coopster

Message Too Old, No Replies

How to create an member's email system within a site

         

impact

3:06 am on Nov 30, 2009 (gmt 0)

10+ Year Member



Hello,

I am trying to design an email system in my site. Its more like members to members email system.

When a member sends an email, the email content is stored into the database and an email notification email is sent to the recipient to let him know that, he has received an email in my site.

I am able to save the email content into database but what i am not able to understand is, how to create an unique id for each email. So that when the email notification is sent, i can create an unique url for that email. Which when clicked should take the member to their mailbox with this message in view mode.

Initially, i thought, i will have an auto generated serial number in my mysql database. Then I will create MD5 on this and insert into URL but now i feel if i have to do this, first i will have to insert the data and then use mysql command to fetch the top most record of any particular emailID, then get the serial number and then create MD5.

Is there any other way out?

Thank you,

Tommybs

12:39 pm on Nov 30, 2009 (gmt 0)

10+ Year Member



You could use the primary key on the message table. If not just store a hash as a unique key on the db that is merely an md5 of the time it was created.

e.g


$msg_hash = md5(date());
$q = @mysql_query("INSERT INTO message(content,hash) VALUES($content, $msg_hash)");

As the msg_hash variable is already stored you can use that in your mail.

$msg = "You have a new message at mysite. go to www.mysite.com?m=$msg_hash to read it";
mail($to, $from...etc.)

Then check that this message hash matches up. You also might benefit from adding the user_to message id to the hash or some other unique user identifier and also checking the user can view the message when they access a page (i.e in case people send messages at exactly the same time )

Tommybs

12:41 pm on Nov 30, 2009 (gmt 0)

10+ Year Member



On another note, if you just wanted to md5 the last inserted id and match up on that instead of writing another query to get the last entered id, you can use the


mysql_insert_id();

function in php the retrieve the id without having to run another query.

impact

4:47 pm on Nov 30, 2009 (gmt 0)

10+ Year Member



Thank you for the help.