Hey guys typically am after your help

I have my site and i need to generate dynamic code to be sent to the mobile via the mobile number.
Its like those which are usualy sent by the gmail or yahoo for verification during creating the email

-Php source codes for generating the dynamic codes ?
-how those codes can be sent to the database and then to the mobile phone?
-Guys i am in need of your help.