1) { if ($parts[0] == "https") { $https = true; $port = "443"; } $host = $parts[1]; } else $host = $nowsmsURL; // parse port number if present $parts = explode(":", $host); if (count($parts) > 1) { $host = $parts[0]; $port = $parts[1]; } // remove trailing slash $parts = explode("/", $host); if (count($parts) > 1) { $host = $parts[0]; } echo "Host: " . $host ."\r\n"; echo "Port: " . $port ."\r\n"; if (https) $sockHost = "tls://" . $host; else $sockHost = $host; echo "sockHost: " . $sockHost ."\r\n"; $mimeFiller = "This is a MIME message\r\n\r\n"; $dc = strlen($mimeFiller); $bo ="-----------------------------mime-boundary-marker"; $fp = fsockopen($sockHost, $port, $errno, $errstr); if (!$fp) { echo "errno: $errno \n"; echo "errstr: $errstr\n"; return "ERROR " . $errno . " - " . $errstr; } fputs($fp, "POST / HTTP/1.0\r\n"); if ($username != "") { $auth = $username . ":" . $password; $auth = base64_encode($auth); fwrite($fp, "Authorization: Basic " . $auth . "\r\n"); } fputs($fp, "User-Agent: NowSMS PHP Script\r\n"); fputs($fp, "Host: $host\r\n"); fputs($fp, "Accept: */*\r\n"); fputs($fp, "Content-type: multipart/form-data; boundary=$bo\r\n"); foreach($data_to_send as $key=>$val) { $ds =sprintf("%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n%s\r\n",$bo,$key,$val); $dc += strlen($ds); } $dc += strlen($bo)+3; fputs($fp, "Content-length: $dc\r\n"); fputs($fp, "\r\n"); fputs($fp, $mimeFiller); foreach($data_to_send as $key=>$val) { $ds =sprintf("%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n%s\r\n",$bo,$key,$val); fputs($fp, $ds ); } $ds = $bo."--\r\n" ; fputs($fp, $ds); $res = ""; while(!feof($fp)) { $res .= fread($fp,1); } fclose($fp); return $res; } // EXAMPLE usage of above functions /* Initialise the MMS Message object wth MmsInit */ $mmsMessage = MmsInit(); /* Set MMS message fields with MmsAddField */ /* "PhoneNumber" is the recipient, and can be a comma deilmited list of recipients or the name of a NowSMS distribution list */ /* "MMSFrom" is the sender - ignored by modems*/ /* "MMSSubject" is the optional subject */ /* "MMSText" is an optional text part of the message. Text parts can also be added as file references */ $mmsMessage = MmsAddField ($mmsMessage, "PhoneNumber", "+447777777777"); // recipient $mmsMessage = MmsAddField ($mmsMessage, "MMSFrom", "447777777777"); // sender $mmsMessage = MmsAddField ($mmsMessage, "MMSSubject", "Subject of Message"); $mmsMessage = MmsAddField ($mmsMessage, "MMSText", "Hello!"); /* Files (usually images) can be added using a local directory path or remote URL. For a local directory path, use MmsAddFile. The last parameter is the MIME content type, e.g., "image/gif", "image/jpeg", "image/png", "text/plain" or "application/smil" ... however, note that current versions of NowSMS ignore the MIME content type when messages are submitted via the interface used by this PHP script. Instead, NowSMS uses the file extension to determine the content type (e.g., ".gif", ".jpg", ".png", ".txt", ".smil" */ // $mmsMessage = MmsAddFile ($mmsMessage, "f:\\temp\\file.gif", "image/gif"); /* To include a file (image) by URL reference, use MmsAddField with field name MMSFile */ $mmsMessage = MmsAddField ($mmsMessage, "MMSFile", "https://www.nowsms.com/wp-content/uploads/2010/10/mainenvelope.png"); /* Set parameters for connecting to the NowSMS server */ $nowsmsHostURL = "https://sample.smshosts.com"; $nowsmsUsername = "username"; /* "SMS Users" account name */ $nowsmsPassword = "password"; /* "SMS Users" account password /* Use MmsSend to send the message. The HTTP response from the server is returned by this function, and this example echoes it */ $x = MmsSend ($nowsmsHostURL, $nowsmsUsername, $nowsmsPassword, $mmsMessage); echo $x; ?>