<?php
function sendsms1($account,$auth,$from,$to,$body,$purl='') {

    $fromEncode = "From=" .  urlencode($from) . "&To=". urlencode($to) . "&Body=" . urlencode($body);

    //echo $fromEncode . "<br>";

    //echo base64_encode("$account:$auth");

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.twilio.com/2010-04-01/Accounts/$account/Messages.json",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => $fromEncode,
        CURLOPT_HTTPHEADER => array(
            "Authorization: Basic " . base64_encode("$account:$auth"),
            'Content-Type: application/x-www-form-urlencoded'
        ),
    ));


    $response = curl_exec($curl);


    $reponseJson =  json_encode($response);
    $tmp = json_decode($reponseJson, true);
    //print_r("<pre>" . $tmp . "</pre>");
    //return $tmp['sid'];
}



