sending an activation code emails how????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
junix
Forum Newbie
Posts: 5
Joined: Tue Sep 25, 2007 2:10 am
Location: MSU, Philippines
Contact:

sending an activation code emails how????

Post by junix »

i just wondering how to send an activation code to emails after a user has registered or filled up the
form , what shall I do? help me Pls.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

mail() the email to them

create an activation code, store it somewhere, check against it when the email is clicked or the activation code is entered.

generating an activation code can be as simple as using rand(), or as complex as you want it to be. I usually just go with something completely random like..

Code: Select all

$activationCode = substr(md5(microtime()), 0, mt_rand(5,12));
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
mrkite
Forum Contributor
Posts: 104
Joined: Tue Sep 11, 2007 4:19 am

Post by mrkite »

I use the following two functions:

Code: Select all

function genID()
{
        $num="";
        for ($i=0;$i<15;$i++) $num.=rand(0,9);
        $sum=0;
        for ($i=0;$i<15;$i++)
        {
                $l=$num[15-($i+1)];
                $sum+=($i&1)?$l:(($l*2)%9);
        }
        if ($sum%10) $num.=10-($sum%10);
        else $num.="0";
        return $num;
}
function checkID($id)
{
        $sum=0;
        $len=strlen($id);
        for ($i=0;$i<$len;$i++)
        {
                $l=$id[$len-($i+1)];
                $sum+=($i&1)?(($l*2)%9):$l;
        }
        return (($sum%10)==0);
}
Which is my implementation of the Luhn Algorithm

Email clients like to wrap urls in weird ways.. making it common for the non-technically proficient to click on a truncated url or to copy and paste only half the number.

This way I can verify that the number is valid. If it's invalid, I can tell them right away that they didn't copy and paste the url correctly. If it is valid, but not found in the database, I can tell them that they've already verified their email address.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: sending an activation code emails how????

Post by califdon »

junix wrote:i just wondering how to send an activation code to emails after a user has registered or filled up the
form , what shall I do? help me Pls.
I have a hunch that you are asking about how to send an email from PHP, rather than how to generate the activation code. scottayy gave you the short answer. If you are running PHP on a server that has an SMTP server configured, sending email is as easy as forming 4 strings and calling the function mail(). Do look up the reference scottayy gave you.
Post Reply