Highly recommend Twilio Cloud Communication, it can be used to send the code via SMS or by a phone call.
Using PHP as an example, here is how it would look -
Text Message
<?php
// Get the Twilio PHP Library from http://twilio.com/docs/libraries
require "Services/Twilio.php";
//Random Code
$code = rand(pow(10, 6-1), pow(10, 6)-1);
// Set your Twilio Account settings
$AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
//Initial Twilio instance
$client = new Services_Twilio($AccountSid, $AuthToken);
//Recipient number - must be +15555555555 format
$recipient = '+18882224444';
$caller_id = '+18008885555'; //Twilio phone number
//Send the message
$sms = $client->account->sms_messages->create(
$caller_id,
$recipient,
"Your activation code is: $code"
);
Phone Call
<?php
// Get the Twilio PHP Library from http://twilio.com/docs/libraries
require "Services/Twilio.php";
// Set your Twilio Account settings
$AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
//Initial Twilio instance
$client = new Services_Twilio($AccountSid, $AuthToken);
$call = $client->account->calls->create(
'9991231234', // From a valid Twilio number
'8881231234', // Call this number
//When the call is connected, code at this URL will be executed
'/say-code.php'
);
say-code.php
<?php
// Get the Twilio PHP Library from http://twilio.com/docs/libraries
require "Services/Twilio.php";
// Random Code
$code = rand(pow(10, 6-1), pow(10, 6)-1);
// Generate TwiML - XML for Twilio
// This will execute when the caller is connected and use Text-To-Speech to
// play their activation code.
// You may also use an MP3 like so:
// $response->play('http://example.com/code.mp3');
$response = new Services_Twilio_Twiml();
$response->say("Your activation code is $code");
print $response;
There are a lot of other helper libraries out there to accomplish this with Twilio. Hope this helps!