Reputation: 193
I am using a service to send sms using php by redirecting to service page (e.g http://example.com?receiver=38383&msg=test)
If I want to send a message to one phone number I can redirect to this page, but I want to send a lot of message using for loop. I can't redirect to the page because it will stop the PHP script. I tried cURL but I don't have any results. Can you help me?
This is the code of cURL:
$path = "http://example.com?receiver=38383&msg=test";
$opts = array(CURLOPT_URL => $path,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => true);
$ch = curl_init();
curl_setopt_array($ch, $opts);
$return = curl_exec($ch);
curl_close($ch);
echo $return;
Upvotes: 1
Views: 1683
Reputation: 13257
function sendSMS($receiver, $message) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com?receiver" . $receiver . "&msg=" . $message);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
echo sendSMS (38383, "test");
Upvotes: 3