E-mail confirmation

Hi,

could you give me a general idea on how to implement an e-mail confirmation system (ex. in order to confirm an account registration).

Thank you.

I guess you want to discuss about the logic, as there is nothing specific to Yii about it.

So, maybe use something like:

  1. Add the user with activated = 0, or add him in a temp table in registration step.

  2. Send activation mail using a link containing a random string (the same string is stored at user record in the database too). Maybe something like a random 8 char word passed through md5()?

  3. When a request comes to the activation controller check the id vs the database and assign "1" to activated column (or move the user record from temp table to main user table). Maybe ask for password confirmation too?

Most of my websites I build has this.  What I do is I have a extra field in my user table called "verified".  It can either contain a verification code that gets emailed to the user, or NULL if the user has already verified.

I agree with the process, it works fine. 

Just a note that you will probably want to send emails immediately rather than waiting for some cron to trigger emails every 15 minutes or so.  Nothing worse than a user having to wait for their activation email.  If you try to send the email within your code, the script will hang until it's finished sending an email.  I fork out a new process therefore the original script completes immediately and the email is also sent immediately. 

Every time a user creates a profile or does anything that requires email notification, I write the email content(to,subject, content, etc) to a temporary table.  I also have a class that is called whenever an email needs to be sent using exec()  It basically checks that temporary table, travels the records, sends the emails and deletes the record once confirmed.  You need to be careful catching any errors or the process will loop forever.  Basically redirect the output of success or failure to a log file… that way the spawned process will complete rather that hang. 

I had a thread on this at pradosoft.comhttp://www.pradosoft…pic,9772.0.html

Let me know if you need more details.

Regards,

R

http://www.pradosoft…pic,9772.0.html