[Advanced Search]

PHP code required: How can i send sms using php program?

In order to send sms from php script, you would be required to call APIs provided by messaging service providers.

Messaging providers are the companies who act as an intermediary between Programmers and Telecom operators. They publish APIs which can integrated into any programming language for adding Addon functionality to your application.

Here is one such simple example.

  • 2Factor is one of the messaging service provider who provides SIMPLE REST APIs for programmers to add SMS sending facility in their program.

    API Documentation:
    API Docs

    Sample code in PHP:

<?php

$YourAPIKey='<YourAPIKey>';
$From='<SenderId>';
$To='<PhoneNumber>';

$Msg='<YourMessage>';

### DO NOT Change anything below this line

$agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';

$url = "https://2factor.in/API/V1/$YourAPIKey/ADDON_SERVICES/SEND/TSMS"; 

$ch = curl_init(); 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_POSTFIELDS,"From=$From&To=$To&Msg=$Msg"); curl_setopt($ch, CURLOPT_USERAGENT, $agent);echo curl_exec($ch); 
curl_close($ch);

?>


User Opinions (0 votes)
No users have voted.

How would you rate this answer?
Helpful
Not helpful

Continue