Akshay
Akshay

Reputation: 123

Sending SMS via PHP

I am woking on my final year project and I would like to send sms to a client via php.

Is there any way in which I can use my cell phone as a GSM modem and send sms via php?

I tried "Ozeki NG - SMS Gateway" but not sure how to send sms via php.

if anyone has used/tried "Ozeki NG - SMS Gateway" then please let me know how to use it properly?

Any suggestions please do let me know.

I have a nokia 701. Can it be used as a gsm modem?.

Thank you

Upvotes: 4

Views: 24059

Answers (5)

vishnu sharma
vishnu sharma

Reputation: 72

I assume that you already have sms service from msg91 using above setup or you can use any sms service providers like Twilio, Nexmo etc. Now i am creating a common function which you can call anywhere in your PHP code to send any type of text sms.

//send otp message
public static function sendMessage($mobile, $message)
{
    $message = urlencode($message);
    $url = sprintf("http://api.msg91.com/api/v2/sendsms?authkey=%s&mobiles=%s&message=%s&sender=%s&route=%s",
        env('MSG91_AUTH_KEY'), $mobile, $message, env('MSG91_SENDER_ID'), env('MSG91_ROUTE'));
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

For more details and step by step execution follow below link :

https://www.lelocode.com/posts/sending-sms-like-otp,-welcome-message,mobile-verification-using-php---lelocode

Upvotes: 0

Grald
Grald

Reputation: 464

Your can try https://www.clickatell.com/ it is easy to use & integrate into your php code you can use http or rest api.

Upvotes: 1

user3144832
user3144832

Reputation: 199

If your phone is android you could use an app such as SMS Gateway API which will turn your phone into a SMS gateway and would allow you to both send and receive messages via PHP.

$URL = "http://v2.smsgateway.me/API/Send/Single.php";

$postdata = http_build_query(
    array(
    'Username' => "[email protected]",
    'Password' => "password",
    'Number' => "+447791064782",
    'Message' => "Hello World!",
    'Device' => 1, //Send from device 1 (optional)
    'SendAt' => (time() + (60 * 60)), //Send in 1 hours time (optional)
    'ExpireAt' => (time() + (60 * 60 * 2)) //Expire in 2 hours time (optional)
    )
);

$opts = array('http' => array('method'  => 'POST', 'header'  => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));

$context  = stream_context_create($opts);

$result = file_get_contents($URL, false, $context);

echo $result;

Upvotes: 1

pal4life
pal4life

Reputation: 3388

Try out this example code from Twilio, I used it during one of the hackathons. Just for demo purpose this may help. Depends on what country though.

http://www.twilio.com/docs/quickstart/php/sms

Upvotes: 3

Jasper
Jasper

Reputation: 76003

American Telcos let you send text messages as emails. I haven't played with this is many years, but I remember Verizon being [Phone #]@vtext.com, where [Phone #] is the 10-digit phone number of the cell phone. There are different domains for the different Telcos that you can lookup. Best of all this is free, rather than having to pay per text message.

Upvotes: 1

Related Questions