Results 1 to 2 of 2

Thread: using CURL to send sms

  1. #1
    Join Date
    Aug 2013
    Thanked 0 Times in 0 Posts

    Default using CURL to send sms

    1: I used this code below to send sms and its working but the problem is that it was the form action that was sending it instead of curl and as such i couldn't be able to print a message eg sms successful or sms sending fails based on the values given to me by the sms resellers

    eg ok means the message was succesful

    2904 means the message could not be sent

    form action = ""

    form action sends the sms instead of

    $Curl_Session = curl_init('http://www.sms_site/smsapi.php');

    2: How do i print that sms messages were sent or not based on the assigned values above

    any help

    below is the working code so far

    echo' <table width="100%" border="0">
                  <td valign="top"><div id="estblshmt-form">
                    <div class="head"><font color=green size=5>Send Bulk SMS</font></div>
    //echo '<form name=form1 method=get action="">';
    echo '<form name=form1 method=POST >';
    echo '<label>Sender ID:</label>';
    echo '<input id="sender"  name="sender"><br><br>';
    echo '<label>Reciever:</label>';
    echo '<input id="recipient"  name="recipient"><br><br>';
    echo '<label>Message:</label>';
    echo '<textarea name="message" id="message"rows="4" cols="50"></textarea><br>';
    //echo '<input id="message"  name="message"><br><br>';
    //echo '<input type=submit name=Submit value=Register>';
    echo'<input type="submit" name="add_subcat" id="add_subcat" value="Send SMS Now!" class="btn btn-info btn-small">';
    echo '</form>';
    echo '</td>';
    echo '</tr>';
    echo '</table>';
    $username = (isset($_POST['username']) ) ? $_POST['username'] : '';
    $password = (isset($_POST['password']) ) ? $_POST['password'] : '';
    $sender = (isset($_POST['sender']) ) ? $_POST['sender'] : '';
    $recipient = (isset($_POST['recipient']) ) ? $_POST['recipient'] : '';
    $message = (isset($_POST['message']) ) ? $_POST['message'] : '';
     $Curl_Session = curl_init('');
     curl_setopt ($Curl_Session, CURLOPT_POST, 1);
     curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "username=$username&password=$password&sender=$sender&recipient=$recipient&message=$message");
     curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($Curl_Session, CURLOPT_RETURNTRANSFER,1);
     $result=curl_exec ($Curl_Session);
    if ($result == 'ok'){
        echo 'message sent';
        elseif ($result == '2904'){
     echo 'message sending failed';
         echo '';
     curl_close ($Curl_Session);

  2. #2
    Join Date
    Aug 2013
    Thanked 0 Times in 0 Posts

    Default Sms api working on local server but not working on hosted server

    In my development enviroment, i enable CURL .when i deployed the code via wamp server, everything works and i was able to send sms when connected to internet.
    when i hosted the code on my linux web hosting account, it displays error shown below and thus cannot send sms.
    below is the error showned

    Not Acceptable
    An appropriate representation of the requested resource /components/com_spc/smsapi.php could not be found on this server.
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    Apache/2.2.26 (Unix) mod_ssl/2.2.26 OpenSSL/1.0.1e-fips DAV/2 mod_bwlimited/1.4 Server at Port 80

    below is the code.

    $data = array(
            'username' => $_POST['username'],
            'password' => $_POST['password'],
            'sender'  => $_POST['sender'],
    'recipient'  => $_POST['recipient'],
    		'message'  => $_POST['message']
        // Send the POST request with cURL
        $ch = curl_init('');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $result = curl_exec($ch); //This is the result from Textlocal
    if(curl_exec($ch) === false) {
    echo '<font color=red size=4><b>Message sending failed' . '</b></font><br />';
    } else {
    echo '<font color=orange size=4><b>Message sent successfully' . '</b></font><br />';
    echo 'Total number of bytes downloaded: ' . curl_getinfo($ch,CURLINFO_SIZE_DOWNLOAD) . '<br />';
    echo 'Total size of all headers received: ' . curl_getinfo($ch,CURLINFO_HEADER_SIZE) . '<br />';
    } else {
                    <form method="post"  style="margin: 5px; padding: 5px;">
                            <table width="100%" border="0" cellspacing="5px" cellpadding="3px">
                                    <td><input name="username" type="hidden" id="username" value="" size="50" style="width: 400px;" /></td>
                                    <td><input name="password" type="hidden" id="password" value="" size="50" style="width: 400px;" /></td>
                                    <td><input name="sender" type="hidden" id="sender" size="50" style="width: 400px;" value=""/></td>
    <input name="recipient" type="text" id="recipient" size="50" style="width: 400px;" value=""/>
                                    <td><textarea name="message" rows="4" cols="90" id="message" style="width: 400px; height: 120px;"></textarea></td>
                                    <td><input type="submit" name="submit" id="add_subcat" value="Send Now!" class="btn btn-info btn-small"></input> <input type="reset" name="Submit2" value="Reset" /></td>

Similar Threads

  1. php socket send receive like curl
    By ggalan in forum PHP
    Replies: 3
    Last Post: 10-16-2012, 01:54 AM
  2. Issue with CURL
    By hemi519 in forum PHP
    Replies: 3
    Last Post: 09-05-2012, 07:57 PM
  3. install CURL for PHP 5 (Godaddy VPS)
    By chetanmadaan in forum PHP
    Replies: 7
    Last Post: 06-14-2010, 11:11 AM
  4. CURL and Javascript? Is it Possible?
    By sysout in forum PHP
    Replies: 0
    Last Post: 09-23-2009, 11:03 AM
  5. cURL define script.
    By cursed in forum Looking for such a script or service
    Replies: 0
    Last Post: 11-08-2007, 02:04 AM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts