Func. for calculating time, sending mail with key, inserting into registration tble