Send an SMS in FuelPHP with Twilio

FuelPHP is a great framework, being developed by some of the CodeIgniter contributes. In this article I will be running through the process of adding a package and setting it up to send SMS’s via Twilio.


  • An instance of FuelPHP.
  • A copy of Fuel-Twilio from GitHub. You can also type php oil package install twilio in shell.


First you will need an account with Twilio. Goto and register, as you will be sending SMS, you will probably want to add some credit too.

Once you have registered, goto and make a note of your account sid and auth token, these will need to go into the package config file.

To send an SMS, Twilio requires you to need a valid ‘from’ number. This can either be a ‘Twilio number or a verified number.

  • Twilio number – A number that Twilio provide, these cost $1 a month.
  • Verified number – A number you own that has bee verified be Twilio.

Follow the instructions on Twilio to set one up.

So at this stage you should have an account sid, auth token and a verified from number.


The first thing you need to do is copy fuel/packages/twilio/config/twilio.php to fuel/app/config/ and open it up in your editor.

Enter your account_sid, auth_token and from items.

Once this is done, sending an SMS is really easy:

class Controller_Welcome extends Controller {
	public function action_index() {
		$twilio_response = $sms->create(array(
			'To' => '+441234567890',
			'From' => Config::get('twilio.from'),
			'Body' => 'A sms message',
		$json = json_encode($twilio_response);
		$response = Response::forge($json);
		$response->set_header('Content-Type', 'application/json');
		return $response;	

Next I will be showing you how to generate TwiML to talk to your customers using FuelPHP!