Skip to content

Instantly share code, notes, and snippets.

@hyrsky
Created May 25, 2018 22:10
Show Gist options
  • Save hyrsky/1a037c14c1fc16d871b738441aff9038 to your computer and use it in GitHub Desktop.
Save hyrsky/1a037c14c1fc16d871b738441aff9038 to your computer and use it in GitHub Desktop.
Send SMS
<?php
class CMSMS
{
static public function buildMessageXml($recipient, $message) {
$xml = new SimpleXMLElement('<MESSAGES/>');
$authentication = $xml->addChild('AUTHENTICATION');
$authentication->addChild('PRODUCTTOKEN', 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
$msg = $xml->addChild('MSG');
$msg->addChild('FROM', 'Whoever');
$msg->addChild('TO', $recipient);
$msg->addChild('BODY', $message);
return $xml->asXML();
}
static public function sendMessage($recipient, $message) {
$xml = self::buildMessageXml($recipient, $message);
$ch = curl_init(); // cURL v7.18.1+ and OpenSSL 0.9.8j+ are required
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://sgw01.cm.nl/gateway.ashx',
CURLOPT_HTTPHEADER => array('Content-Type: application/xml'),
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $xml,
CURLOPT_RETURNTRANSFER => true
)
);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
$message = $_POST["message"];
if (strlen($message) > 160) {
http_response_code(400);
exit();
}
$file = fopen("../numerot.txt", "r");
while(!feof($file)) {
$line = trim(fgets($file));
if (empty($line)) {
continue;
}
$response = CMSMS::sendMessage($line, $message);
echo $response;
}
fclose($file);
echo "sent";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment