Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-10-2010, 08:33 AM   PM User | #1
idalatob
Regular Coder

 
Join Date: Sep 2007
Location: Grahamstown, South Africa
Posts: 237
Thanks: 6
Thanked 17 Times in 17 Posts
idalatob is on a distinguished road
Send SMS code

Hi there,

I thought a lot of you guys might find this interesting, its an API to send SMS's from a browser etc. Just keep in mind that you have to set up an account with panaceamobile @ www.panaceamobile.com! But sending a sms with them is generally a whole lot cheaper anyway!

Enjoy the API:
PHP Code:
<?php

function send_message($username$password$from$to$message$track_delivery 0) {
    
$url "http://api.panaceamobile.com/sendsms?1";
    
$data = array(
        
"to" => $to,
        
"from" => $from
        
"dlr-mask" => $track_delivery,
        
"text" => $message,
        
"username" => $username,
        
"password" => $password
    
);
        
    foreach(
$data as $key => $val) {
        
$data[$key] = urlencode($val);
    }



    
$str $url;
    foreach(
$data as $key => $val) {
        
$str .= "&{$key}={$val}";
    }

    
$ch curl_init();
    
curl_setopt($chCURLOPT_URL$str);
    
curl_setopt($chCURLOPT_HEADER0);
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
$res curl_exec($ch);

    if(
$res !== FALSE) {
        if(
        (
strpos($res"Accepted") === FALSE) &&
        (
strpos($res"Queued") === FALSE) &&
        (
strpos($res"Sent") === FALSE)
        )
        return 
false;
        return 
true;
    }
    return 
false;
}

$to "44325321234";
$from "4432532021";


if(
send_message("myusername""mypassword"$to$from"Hello Messaging!"1)) {
    echo 
"Message Sent!";
} else {
    echo 
"Message Failed!";
}


?>
idalatob is offline   Reply With Quote
Old 09-10-2010, 08:34 AM   PM User | #2
idalatob
Regular Coder

 
Join Date: Sep 2007
Location: Grahamstown, South Africa
Posts: 237
Thanks: 6
Thanked 17 Times in 17 Posts
idalatob is on a distinguished road
Quite useful if you are implementing a solution with a client who needs SMS support! :-D
idalatob is offline   Reply With Quote
Old 03-27-2011, 05:17 AM   PM User | #3
textmedia
Banned

 
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
textmedia is an unknown quantity at this point
Thumbs up

Nice share i will try this an see how it works............
textmedia is offline   Reply With Quote
Old 03-27-2011, 06:51 AM   PM User | #4
kelsie
New to the CF scene

 
Join Date: Mar 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
kelsie is an unknown quantity at this point
Hmm this could be useful, thanks for sharing!
kelsie is offline   Reply With Quote
Old 01-14-2012, 05:20 PM   PM User | #5
12k
New Coder

 
Join Date: Jan 2012
Posts: 29
Thanks: 0
Thanked 6 Times in 6 Posts
12k is an unknown quantity at this point
I always prefer just simply sending it using a smtp. Only downside is some phone carriers consider it as a data charge even though its a text message. Its free for you to send texts anyways
12k is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:03 AM.


Advertisement
Log in to turn off these ads.