Skip to content

Instantly share code, notes, and snippets.

@Jerry-Fix
Created May 11, 2013 14:40
Show Gist options
  • Save Jerry-Fix/5560136 to your computer and use it in GitHub Desktop.
Save Jerry-Fix/5560136 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
// The service you're using. Choices include clickatell, budgetsms, nexmo and clockwork
$service = 'emay';
// The API key.
$apikey = "YOUR_APIKEY;
// Username and password. With BudgetSMS use userid as password. Username not needed for Nexmo or Clockwork
$user = "";
$password = "YOUR_PASSWD";
// The sender name / number. This has to conform to your service provider's
//+regulations.
$from = "Zabbix";
// Where should this script log to? The directory must already exist.
$logfilelocation = "/var/log/zabbix/sms/";
// if debug is true, log files will be generated
$debug = false;
/**********************************************************************
!! Do not change anything below this line unless
you _really_ know what you are doing !!
**********************************************************************/
if (count($argv)<3) {
die ("Usage: ".$argv[0]." recipientmobilenumber \"subject\" \"message\"\n");
}
if ( $debug )
file_put_contents($logfilelocation."sms_alert_" . $service . "_".date("YmdHis"), serialize($argv));
$to = $argv[1];
$subject = $argv[2];
$message = $argv[3];
$text = $subject.": ".$message;
//$text = $message;
$apiargs = array(
"cdkey" => $apikey,
"password" => $password,
"phone" => $to,
"message" => $text,
);
$baseurl = "http://sdkhttp.eucp.b2m.cn/sdkproxy/sendsms.action";
$params = "";
foreach ($apiargs as $k=>$v) {
if ( $params != "" ) {
$params .= "&";
}
$params .= $k."=".urlencode($v);
}
$url = $baseurl . '?' . $params;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url );
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if ( $result === false ) {
file_put_contents($logfilelocation."sms_alert_" . $service . "_error_".date("YmdHis"), curl_error($curl));
die(curl_error($curl)."\n");
} else {
if ( $debug || $result != 100 )
file_put_contents($logfilelocation."sms_alert_" . $service . "_answer_".date("YmdHis"), $result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment