How Do You Send SMS Using PHP Script?

I

f you are developing eCommerce project than definitely you need to add feature send sms notification for site users. Sending message to user can also be used to send coupon code, let user know your bill or statement is ready etc. Sending SMS from php script is simple and tricky. This tutorial shows quick and easy way to send sms using php script. Hope its cool and help you in development. We will use twilio sms library to send SMS. Twilio is best library for sending or receiving call as well as message.

Create Twilio Account

Very first step to create twilio account. Twilio provides limited number of sms in trial account. Remember if you are using twilio trial account than you need to verity number first on twilio on which you want to receive text message. Otherwise you will not get text message.

Directory Structure

index.php
lib
-- Twilio
-- Twilio.php

index.php

Contains basic form which inputs phone number and message from user.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

<body>

<form action=""name="frmMessage"method="post">

<div>Send SMS using PHP script</div>

<div>

<label>Phone Number:</label>

<input type="text"name="phoneNumber"value=""/>

</div>

<div>

<label>Message:</label>

<textarea name="message"></textarea>

</div>

<div>

<input type="submit"value="Send"/>

</div>

</form>

</body>

Code To Send Message

Include twilio library to access send sms service. Download twilio php library from here. Replace your twilio Account id, Authentication token and twilio number in below code. We have added validations for phone number and message than initialised twilio library.

Categories

Sgeek is how to blog maintained by Gopal Joshi. Gopal is Software Engineer and Blogger by passion and love to building web applications. Sgeek will share How To Technology Stuff, Tutorials of various technologies such as PHP, Symfony, Python, NodeJS, Frameworks and more.