0

I have some data I want to sent as a HTTP POST request to a specific URL. I have googled and read for hours but I am stuck on writing the actually code.

I can created the complete URL I need and if I echo out the below sms_url variable and manually paste it into the browser address bar, the sms is sent successfully. My question is how do I make PHP do this automatically after a button click?

    <?php
    $customer = '4512121212';
    //Create variable $sms_url to send sms to customer
    // The neccesary variables
    $sms_message = ("this is a test");
    $sms_url = "http://www.theurl.com/sms/";
    $sms_url .= "?message=" . urlencode($sms_message); //messages
    $sms_url .= "&recipient=$customer"; // Recipient
    $sms_url .= "&username=x"; // Username
    $sms_url .= "&password=x"; // Password
    $sms_url .= "&from=" . urlencode("company name"); // Sendername
    $sms_url .= "&utf8=1"; //UTF8 encoded
    echo $sms_url. "<br>";

now what??
    ?>

UPDATE and EDIT

I tested with curl but it is not working?

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $sms_url);
$content = curl_exec($ch);
var_dump($content);
?>

Any suggestions on what could be wrong?

UPDATE AND SOLVED

The below code works.

$curl = curl_init($sms_url);
$errmsg  = curl_error( $curl );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
curl_close ($curl);  
?>
Nomis
  • 437
  • 1
  • 4
  • 13

1 Answers1

-3

update: performing a GET request instead of a POST request (according to your question i can just assume that a GET request works for sure) you can do it like this without redirecting the user:

http_get($sms_url);

if you are still looking for a post request, you might check out http_post_data()

low_rents
  • 4,481
  • 3
  • 27
  • 55