Jump to content

Twilio and php - SMS help please


MrScabbyUnderpants

Recommended Posts

Hello all,

 

I need some help with a problem I have.

 

I have wrote some software in Java and all is going well - it monitors various sites and their associated shifts. When someone arrives on a site they SMS their site number to a Twilio number I have set up.

 

I'm quite new to programming and this is my first ever application. The application needs to periodically go online and collect any new SMS messages. I need help with this part.

 

I'm going to use Twilio for this, they have all sorts of API's for various languages but because I'm new to all this and know ZIP about RESTful services I need some help please.

 

https://twilio.github.io/twilio-php/

 

https://www.twilio.com/docs/libraries/php

 

When an SMS is received by Twilio, they make a call to a URL I set up. So if this is php they will make a call to the php script you place on your server, it says in the documentation that this call has all the SMS information with it. So all I want is a simple php script that will collect the information and save it to the end of a txt file on the server. I can then go and collect it periodically by my Java application and parse them into objects for processing and then delete the txt file on the server.

 

I have searched endlessly for a script I can work from as reference but all I seem to find are examples of how to send SMS

 

I need to receive SMS first, can someone bail me out here, I think while all this has been a great experience I really need to finish it off and Im suck at this part of the work?

 

I have tried to read the Twilio docs and help but they are a bit too technical for me at the moment and need some help to get me going!

 

thanks folks, great site.

 

Phil

 

 

Link to comment
Share on other sites

Your callback URL just needs to accept some POST data and store it somewhere. When Twilio calls it they will provide a bunch of details about the SMS as POST fields. You extract the data you want and do whatever you need to do with it.

 

For example:

<?php
$from = $_POST['From'];
$to = $_POST['To'];
$message = $_POST['Body'];

$handle = fopen('log.csv', 'a');
fputcsv($handle, [$from, $to, $message]);
fclose($handle);
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.