47

How to send an SMS from a web server written in PHP?

exebook
  • 32,014
  • 33
  • 141
  • 226
Palani
  • 1,891
  • 7
  • 31
  • 42
  • 1
    http://www.ozekisms.com/php-sms-api-asp-sms-api/index_p_php_q_ow_page_number_e_327opt.html – miku Dec 21 '09 at 11:51
  • possible duplicate of [SMS from web application](http://stackoverflow.com/questions/432944/sms-from-web-application) – sth May 08 '10 at 13:29
  • The other (still existing) dupe is: [any good php tutorial on how to send sms to phones?](http://stackoverflow.com/q/1022597/367456) – hakre Jan 21 '13 at 11:01
  • 1
    Because this still shows up at search results I would have liked to add a sample request like this one: https://github.com/46elks/46elks-getting-started/blob/master/code-examples/PHP/sendsms.php that I think would have been helpful to others wondering the same thing and actually looking for PHP example with code. – Alisso Nov 14 '17 at 10:30
  • Great question! Thanks for posing it. – Vladimir Despotovic Mar 15 '21 at 17:15

3 Answers3

41

Clickatell is a popular SMS gateway. It works in 200+ countries.

Their API offers a choice of connection options via: HTTP/S, SMPP, SMTP, FTP, XML, SOAP. Any of these options can be used from php.

The HTTP/S method is as simple as this:

http://api.clickatell.com/http/sendmsg?to=NUMBER&msg=Message+Body+Here

The SMTP method consists of sending a plain-text e-mail to: sms@messaging.clickatell.com, with the following body:

user: xxxxx
password: xxxxx
api_id: xxxxx
to: 448311234567
text: Meet me at home

You can also test the gateway (incoming and outgoing) for free from your browser

kanlukasz
  • 1,103
  • 19
  • 34
Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443
  • I've tried to use the HTTP/S method and it is returning a message tracking ID with some code. But I'm not receiving any text. Why is this? – WTFZane Jul 13 '16 at 15:31
  • 2
    These Links are alas dead now - try https://www.clickatell.com/pricing-and-coverage/message-pricing/#step-1 – mplungjan Mar 13 '17 at 08:39
  • 2
    why do I need to use some server if it is not free.. – fdrv Feb 10 '18 at 11:25
17

PHP by itself has no SMS module or functions and doesn't allow you to send SMS.

SMS ( Short Messaging System) is a GSM technology an you need a GSM provider that will provide this service for you and may have an PHP API implementation for it.

Usually people in telecom business use Asterisk to handle calls and sms programming.

Elzo Valugi
  • 27,240
  • 15
  • 95
  • 114
4

You need to subscribe to a SMS gateway. There are thousands of those (try searching with google) and they are usually not free. For example this one has support for PHP.

B.S.B.
  • 330
  • 2
  • 10
Andreas Bonini
  • 44,018
  • 30
  • 122
  • 156