Tuesday, 26 March 2013

Sending and Receiving Messages using PHP and GoogleVoice


Sending and Receiving Messages using PHP and GoogleVoice

Sending
After reading two articles in Arvin Castro’s blogXHTTP and Google Voice SMS using PHP I decided that it would great if I could take it all that and put it into a one usable PHP class with a simple API. This way I am now able to send text messages through Google Voice within my other projects.
The API of the Google Voice class is pretty simple:

// Connects to Google Voice servers
public function connect($email, $password)
// Sends a text message
public function send($number, $message)
// Validates if a given $text is a US phone number
public function checkPhone($text)

Download class.gvoice.php source code
Receiving
After a litte more thinking I figure out a way to receive messages from Google Voice too. All you need to do is set up forwarding and you are pretty much set.
- In Google Voice website go to Voice settings, then set Text Forwarding to forward text messages to your email (you can add another email using “Add a new email address” link next to Voicemail notifications).
- Once you do this, every text message you receive will be sent to you by email. Next step, is to set up a Forwarder with your web host (or your personal server) to pipe all the email (specified above) to a PHP script (receive.php attached with this post). Example pipe could be:

| /usr/local/bin/php /full/path/to/receive.php

- Modify receive.php to match your needs.

No comments:

Post a Comment