3 //sms.todosv.com wrapper
6 function do_post_request($url, $data, $optional_headers = null)
8 $params = array('http' => array('method' => 'POST','content' => $data));
9 if ($optional_headers !== null) {
10 $params['http']['header'] = $optional_headers;
12 $ctx = stream_context_create($params);
13 $fp = @fopen
($url, 'rb', false, $ctx);
15 echo "Problem with $url, $php_errormsg". "\n";
17 $response = @stream_get_contents
($fp);
18 if ($response === false) {
19 echo "Problem reading data from $url, $php_errormsg". "\n";
24 function tsv_sms_enviar($telefono, $mensaje, $firma){
25 $datos = array('telefono' => $telefono, 'mensaje' => $mensaje, 'firma' => $firma, 'enviar' => '¡Enviar Mensaje!');
26 return do_post_request('http://sms.todosv.com/index.php?visual=estado', http_build_query($datos));
30 $email = file_get_contents("php://stdin");
33 $lines = explode("\n", $email);
41 $splittingheaders = true;
43 for ($i=0; $i < count($lines); $i++
) {
44 if ($splittingheaders) {
46 $headers .= $lines[$i]."\n";
48 // look out for special headers
49 if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
50 $subject = $matches[1];
52 if (preg_match("/^From: .*<(.*)>.*/", $lines[$i], $matches) && !$from) {
55 if (preg_match("/^To: [<]{0,1}(.*)@/", $lines[$i], $matches) && !$to) {
58 if (preg_match("/^X-Forwarded-For: (.*) .*/", $lines[$i], $matches)) {
61 if (preg_match("/^X-Forwarded-To: (.*)@/", $lines[$i], $matches)) {
66 // not a header, but message
67 $message .= $lines[$i]."\n";
70 if (trim($lines[$i])=="") {
71 // empty line, header section has ended
72 $splittingheaders = false;
76 $message = substr(str_replace("\n"," ",$message),0,110);
78 //@file_put_contents("d_".time(),$email);
79 //echo "FROM:" . $from . "\n";
80 //echo "TO:" . $to . "\n";
81 //echo "SUBJECT:" . $subject . "\n";
82 //echo $message . "\n";
83 if ( stristr($to,"_r") ) {
85 $to = str_replace("_r","",$to);
90 $body = tsv_sms_enviar($to, $subject, $from);
91 $headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1' . "\r\n" . 'From: robot@sms.todosv.com' ."\r\n" . 'Reply-To: no_responder_aqui@todosv.com' . "\r\n";
92 if ($flag_mail) @mail
($from,"Estado del mensaje a $to","<html><head><title>Correo de respuesta solicitado por su mensaje enviado a $to</title></head><body>".$body."</body></html>", $headers);