Clickatell PHP client. A simple library to send SMS through the Clickatell SMS gateway.


send SMS using Clickatell API first we need to to install Clickatell PHP library using composer command create a composer dot PHP file and run the following command it will automatically download it necessary files for Clickatell 

composer.json

{
    "require": { 
        "arcturial/clickatell": "*"
    } 
}

composer install

#index.php

<?php
include_once './vendor/autoload.php';

use Clickatell\Rest;
use Clickatell\ClickatellException;
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
        <link href="style.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
        <div class="container">
            <h3>Send texr SMS Clickatell</h3>
            <?php
            if (isset($_POST['message']) && isset($_POST['numbers'])) {
                $clickatell = new \Clickatell\Rest('338gVvNrTtCwwqC_n5KIMw==');
             // Full list of support parameters can be found at https://www.clickatell.com/developers/api-documentation/rest-api-request-parameters/


                $nuber_array = explode(',', $_POST['numbers']);

                if (empty($_POST['message']) || empty($_POST['numbers'])) {
                    echo "Please type message and at least one number.";
                }
                ?>
                <div style="max-height: 150px;overflow-y: auto;width: 100%;">
                    <?php
                    try {
                        $result = $clickatell->sendMessage(['to' => $nuber_array, 'content' => $_POST['message']]);

                        foreach ($result as $message) {



                            echo "Message send successfully: " . $message['to'] . "<br>";
                        }
                        ?>
                    </div>
                        <?php
                    } catch (ClickatellException $e) {
                        // Any API call error will be thrown and should be handled appropriately.
                        // The API does not return error codes, so it's best to rely on error descriptions.
                        var_dump($e->getMessage());
                    }
                }
                ?>
            <form action="" method="post">
                <div class="float-left comman">
                    <textarea placeholder="Message" id="message" name="message"></textarea>
                </div>

                <div class="float-rigth comman">
                    <textarea placeholder="Phone Number List" id="numbers" name="numbers"></textarea>
                </div>

                <div style="clear: both">
                    <input type="submit"  value="Sent" style="width: 100%;background: skyblue;padding: 10px 20px;w">
                </div>
            </form>
        </div>
        <script src="https://code.jquery.com/jquery-2.2.4.min.js" type="text/javascript"></script>

    </body>
</html>

#style.css


/* 
    Created on : Sep 15, 2018, 2:39:58 PM
    Author     : Gajanand Rathor 
*/


body{
    background: #ccc;
    margin: 0;

    padding: 0;
}

.container{
    max-width: 600px;
    margin: 100px auto;
    font-family: 'Roboto', sans-serif;
    background: #fff;
    padding: 10px 50px 50px 30px;
    box-shadow: 7px 7px 20px 0px #00000038;
    border-radius: 5px;
}

.comman{
    width: 50%;
    display: inline-block;
    float: left;
}

.comman textarea{
    width: 100%; 
    border: 1px solid #ccc;
    min-height: 250px;
    padding: 20px;
    box-sizing: border-box;
    margin: 10px;
}

.comman textarea:focus{
    outline: none;
}

#submit-btn{
    width: 100%;
    padding: 15px 20px;
    border: none;
    margin: 10px;
    background: #638cc4;
    font-weight: bold;
    color: #fff;
    margin-top: 0;
    border-radius: 5px;
}

/*custom radio button style start*/

.cntr {
    margin: auto;
}

.btn-radio {
    cursor: pointer;
    display: inline-block;
    float: left;
    -webkit-user-select: none;
    user-select: none;
}
.btn-radio:not(:first-child) {
    margin-left: 20px;
}
@media screen and (max-width: 480px) {
    .btn-radio {
        display: block;
        float: none;
    }
    .btn-radio:not(:first-child) {
        margin-left: 0;
        margin-top: 15px;
    }
}
.btn-radio svg {
    fill: none;
    vertical-align: middle;
}
.btn-radio svg circle {
    stroke-width: 2;
    stroke: #C8CCD4;
}
.btn-radio svg path {
    stroke: #008FFF;
}
.btn-radio svg path.inner {
    stroke-width: 6;
    stroke-dasharray: 19;
    stroke-dashoffset: 19;
}
.btn-radio svg path.outer {
    stroke-width: 2;
    stroke-dasharray: 57;
    stroke-dashoffset: 57;
}
.btn-radio input {
    display: none;
}
.btn-radio input:checked + svg path {
    transition: all 0.4s ease;
}
.btn-radio input:checked + svg path.inner {
    stroke-dashoffset: 38;
    transition-delay: 0.3s;
}
.btn-radio input:checked + svg path.outer {
    stroke-dashoffset: 0;
}
.btn-radio span {
    display: inline-block;
    vertical-align: middle;
}

/*custom radio button style end*/

Run the following code and see the result output


Download source code

Are you facing problems in understanding this article? download source code now