invio sms multipli dal prorio sito

Marco196943

Utente Attivo
19 Ago 2012
66
0
0
Eccomi appena registrato fresco, fresco.
Come già detto nella presentazione iniziale, dovrei rompervi le scatole un pochino pochino...
Sto cercando di inserire nel mio sito, la possibilità di inviare degli sms multipli di promozioni flash, ho scaricato dal sito latintsms un piccolo script per l'invio degli sms.
ora dovrei adattarlo alle mie esigenze:
il mio primo punto è quello di recuperare tutti i numeri di telefono dal db facendo in modo che ogni numero finisca con il punto e virgola , ho creato una query ma mi da solo un numero di telefono.
per ora mi fermerei qui sennò pare brutto tutto insieme:cool:
Ringrazio in anticipo a chi voglia aiutarmi
vi posto il mio codice

PHP:
<?php require_once('../../Connections/iscritti.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_iscritti, $iscritti);
$query_Rs_telefono = "SELECT telefono FROM iscrizioni ORDER BY telefono ASC";
$Rs_telefono = mysql_query($query_Rs_telefono, $iscritti) or die(mysql_error());
$row_Rs_telefono = mysql_fetch_assoc($Rs_telefono);
$totalRows_Rs_telefono = mysql_num_rows($Rs_telefono);
?>
<?php


/*
###SCRIPT DI ESEMPIO PER INVIO SMS DI LATINETSMS.IT###
Per tutte le funzionalità e gli script completi di invio SMS e documentazione 
consultare il sito http://www.latinetsms.it/download/
*/

function do_post($host,$uri,$values) {

if (!($socket = fsockopen($host, 80, $errno, $errstr))) return false;

$reqbody='';
while (list($k,$v) = each($values)) $reqbody .= $k."=".urlencode($v)."&";
$contentlength = strlen($reqbody);
$req =
"POST $uri HTTP/1.0\r\n".
"Host: $host\n". "User-Agent: SMS POST AGENT\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: $contentlength\r\n\r\n".
$reqbody."\r\n";

if (fputs($socket, $req) < 0 ) return false;
while (!feof($socket)) $result[] = trim(fgets($socket, 4096));
fclose($socket);

if (is_array($result)) return $result;
return false;
}

function SMS_Send($login,$password,$message,$dest,$sender,$flash,$quality,$notify,$wappush,$quantity,$tspan,$userip) {

$VALS = array(
		'login' => $login,
		'password' => $password,
		'message' => $message,
		'dest' => $dest,
		'sender' => $sender,
		'flash' => $flash,
		'quality' => $quality,
		'notify' => $notify,
		'wappush' => $wappush,
		'quantity' => $quantity,
		'timespan' => $tspan,
		'userip' => $userip
		);

$resp = do_post("www.pannellosms.com","/smspost.php",$VALS);

if (!is_array($resp)) return array(false,0);
if (!ereg("OK",$resp[0])) return array(false,0);
foreach ($resp as $ll) if (ereg("^CREDITS:(.*)$",$ll,$p)) return array(true,$p[1]);
return array(false,0);
}

$login		= 'xxxxxxxxxxxxxx';	//nome utente
$password	= 'xxxxxxxxxxxxx';	//password utente

if(isset($_POST["dest"]) && isset($_POST["message"])){
	list ($status,$credits) = SMS_Send($login,$password,$_POST["message"],$_POST["dest"],$_POST["sender"],0,'Alta',$_POST["notify"],'',0,0,$HTTP_SERVER_VARS['REMOTE_ADDR']);
	$output = ($status) ? 'Messaggio inviato. Credito residuo: '.$credits.'<br>' : 'Errore di invio del messaggio<br><br>';
}
?>
<body bgcolor="#D7E6EA">
<table align="center">
  <form action="inviosms.php" method="POST">
    <tr> 
      <td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b><?php echo @$output; ?></b></font></td>
    </tr>
    <tr> 
      <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Messaggio:</font></td>
      <td> 
        <textarea name="message" rows="5" cols="40" wrap="virtual"></textarea>
      </td>
    </tr>
    <tr> 
      <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Destinatario:</font></td>
      <td>
          <textarea name="dest" cols="15"><?php echo $row_Rs_telefono['telefono']; ?></textarea>
          </td>
    </tr>
    <tr> 
      <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Mittente:</font></td>
      <td> 
        <input type="text" name="sender" size="10">
      </td>
    </tr>   
    <tr> 
      <td colspan=2> 
        <div align="center"> 
          <input type="submit" value="Invia">
        </div>
      </td>
    </tr>
  </form>
</table>
<div align="center"></div>
<?php
mysql_free_result($Rs_telefono);
?>
 
Ultima modifica di un moderatore:
ciao
recuperare tutti i numeri di telefono dal db facendo in modo che ogni numero finisca con il punto e virgola
intanto come vuoi recuperarli?
una stringa unica es.
$numeri="3332569;356987;123456;789321;";
o singolamnete es. con un array?
nel primo caso potresti fare
PHP:
<?php
//.......
mysql_select_db($database_iscritti, $iscritti);
$query_Rs_telefono = "SELECT telefono FROM iscrizioni ORDER BY telefono ASC";
$Rs_telefono = mysql_query($query_Rs_telefono, $iscritti) or die(mysql_error());
//$row_Rs_telefono = mysql_fetch_assoc($Rs_telefono);
$totalRows_Rs_telefono = mysql_num_rows($Rs_telefono);
if($totalRows_Rs_telefono> 0){
	$numeri="";
	while($riga=mysql_fetch_array($Rs_telefono)){
		$numeri.=$riga['telefono'].";";//se non ti serve eventualmente poi togli l'ultimo ;
		//ottieni la stringa 3332569;356987;123456;789321; ecc....
	}
}else{
	echo "non ci sono numeri nel db";
}
//........
?>
nel secondo
PHP:
<?php
//.......
mysql_select_db($database_iscritti, $iscritti);
$query_Rs_telefono = "SELECT telefono FROM iscrizioni ORDER BY telefono ASC";
$Rs_telefono = mysql_query($query_Rs_telefono, $iscritti) or die(mysql_error());
//$row_Rs_telefono = mysql_fetch_assoc($Rs_telefono);
$totalRows_Rs_telefono = mysql_num_rows($Rs_telefono);
if($totalRows_Rs_telefono>0){
	$numeri=array();
	while($riga=mysql_fetch_array($Rs_telefono)){
		$numeri[]=$riga['telefono'].";";
		/*ottieni un array del tipo
		$numeri[0] => 3332569;
		$numeri[1] => 356987;
		$numeri[2] => 123456;
		ecc....
		*/
	}
}else{
	echo "non ci sono numeri nel db";
}
//........
?>

p.s.
guarda che in $login = xxxxxxxxxxxxxx'; //nome utente
ti eri dimenticato un apice
$login = 'xxxxxxxxxxxxxx'; //nome utente
 
Ultima modifica:
Carisssimo!!!!

Ti ringrazio per la tua celerità, ma oggi è domenica, e c'è il sole, non mi aspettavo tanta grazia:fonzie:
hai colto nel segno, con un array è perfetto, ho controllato il tuo codice ed è moto interessante la costruzzione dell'array, me lo son già segnato:)
ho provato come hai detto tu con la query e l'array, poi nel form nella casella telefono ho provato a recuperarla con <?php echo $telefono ?>,o <?php echo $riga ?> ma senza risultati non visualizzo i due numeri di telefono memorizzati nel database dove mi sto impicciando?:crying:

ciao

intanto come vuoi recuperarli?
una stringa unica es.
$numeri="3332569;356987;123456;789321;";
o singolamnete es. con un array?
nel primo caso potresti fare
PHP:
<?php
//.......
mysql_select_db($database_iscritti, $iscritti);
$query_Rs_telefono = "SELECT telefono FROM iscrizioni ORDER BY telefono ASC";
$Rs_telefono = mysql_query($query_Rs_telefono, $iscritti) or die(mysql_error());
//$row_Rs_telefono = mysql_fetch_assoc($Rs_telefono);
$totalRows_Rs_telefono = mysql_num_rows($Rs_telefono);
if($totalRows_Rs_telefono> 0){
	$numeri="";
	while($riga=mysql_fetch_array($Rs_telefono)){
		$numeri.=$riga['telefono'].";";//se non ti serve eventualmente poi togli l'ultimo ;
		//ottieni la stringa 3332569;356987;123456;789321; ecc....
	}
}else{
	echo "non ci sono numeri nel db";
}
//........
?>
nel secondo
PHP:
<?php
//.......
mysql_select_db($database_iscritti, $iscritti);
$query_Rs_telefono = "SELECT telefono FROM iscrizioni ORDER BY telefono ASC";
$Rs_telefono = mysql_query($query_Rs_telefono, $iscritti) or die(mysql_error());
//$row_Rs_telefono = mysql_fetch_assoc($Rs_telefono);
$totalRows_Rs_telefono = mysql_num_rows($Rs_telefono);
if($totalRows_Rs_telefono>0){
	$numeri=array();
	while($riga=mysql_fetch_array($Rs_telefono)){
		$numeri[]=$riga['telefono'].";";
		/*ottieni un array del tipo
		$numeri[0] => 3332569;
		$numeri[1] => 356987;
		$numeri[2] => 123456;
		ecc....
		*/
	}
}else{
	echo "non ci sono numeri nel db";
}
//........
?>

p.s.
guarda che in $login = xxxxxxxxxxxxxx'; //nome utente
ti eri dimenticato un apice
$login = 'xxxxxxxxxxxxxx'; //nome utente
 
Ciao

Mi intrometto un'attimo

PHP:
echo $telefono;
echo $riga;

Non esiste nessuna variabile $telefono o $riga.



I numeri di telefono devi visualizzarli dall'array $numeri:

PHP:
$num_totale_di_numeri=count($numeri); //trovo il numero totale dei numeri

for ($n=0; $n<$num_totale_di_numeri; $n++) {

echo $numeri[$n];

}


Se vuoi giocare con gli array guarda qui: link :)
 
Ultima modifica di un moderatore:
Scusate...

come posso potrei, abbracciarv, e stringervi forte forte, e dirvi guardandovi negli occhi.... GRAZZZZZZZZZIIIIIIIIIEEEEEEEEE:fonzie:
 
Ora se puo' essere utile....

QUESTO è IL CODICE COMPLETO GRAZIE AL VOSTRO AIUTO DI INVIO DI SMS MULTIMPLI IN PHP


PHP:
<?php  include('../../Connections/iscritti.php'); 
//.......
mysql_select_db($database_iscritti, $iscritti);
$query_Rs_telefono = "SELECT telefono FROM iscrizioni ORDER BY telefono ASC";
$Rs_telefono = mysql_query($query_Rs_telefono, $iscritti) or die(mysql_error()); 
//$row_Rs_telefono = mysql_fetch_assoc($Rs_telefono);
$totalRows_Rs_telefono = mysql_num_rows($Rs_telefono);
if($totalRows_Rs_telefono>0){
    $numeri=array();
    while($riga=mysql_fetch_array($Rs_telefono)){
        $numeri[]=$riga['telefono'].";";
        /*ottieni un array del tipo
        $numeri[0] => 3332569;
        $numeri[1] => 356987;
        $numeri[2] => 123456;
        ecc....
        */
    }
	
}else{
    echo "non ci sono numeri nel db";
}
//........ 
?>
<?php


/*
###SCRIPT DI ESEMPIO PER INVIO SMS DI LATINETSMS.IT###
Per tutte le funzionalità e gli script completi di invio SMS e documentazione 
consultare il sito http://www.latinetsms.it/download/
*/

function do_post($host,$uri,$values) {

if (!($socket = fsockopen($host, 80, $errno, $errstr))) return false;

$reqbody='';
while (list($k,$v) = each($values)) $reqbody .= $k."=".urlencode($v)."&";
$contentlength = strlen($reqbody);
$req =
"POST $uri HTTP/1.0\r\n".
"Host: $host\n". "User-Agent: SMS POST AGENT\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: $contentlength\r\n\r\n".
$reqbody."\r\n";

if (fputs($socket, $req) < 0 ) return false;
while (!feof($socket)) $result[] = trim(fgets($socket, 4096));
fclose($socket);

if (is_array($result)) return $result;
return false;
}

function SMS_Send($login,$password,$message,$dest,$sender,$flash,$quality,$notify,$wappush,$quantity,$tspan,$userip) {

$VALS = array(
		'login' => $login,
		'password' => $password,
		'message' => $message,
		'dest' => $dest,
		'sender' => $sender,
		'flash' => $flash,
		'quality' => $quality,
		'notify' => $notify,
		'wappush' => $wappush,
		'quantity' => $quantity,
		'timespan' => $tspan,
		'userip' => $userip
		);

$resp = do_post("www.pannellosms.com","/smspost.php",$VALS);

if (!is_array($resp)) return array(false,0);
if (!ereg("OK",$resp[0])) return array(false,0);
foreach ($resp as $ll) if (ereg("^CREDITS:(.*)$",$ll,$p)) return array(true,$p[1]);
return array(false,0);
}

$login		= 'XXXXXX';	//nome utente
$password	= 'XXXXXX';	//password utente

if(isset($_POST["dest"]) && isset($_POST["message"])){
	list ($status,$credits) = SMS_Send($login,$password,$_POST["message"],$_POST["dest"],$_POST["sender"],0,'Alta',$_POST["notify"],'',0,0,$HTTP_SERVER_VARS['REMOTE_ADDR']);
	$output = ($status) ? 'Messaggio inviato. Credito residuo: '.$credits.'<br>' : 'Errore di invio del messaggio<br><br>';
}
?>
<body bgcolor="#D7E6EA">
<table align="center">
  <form action="inviosms.php" method="POST">
    <tr> 
      <td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b><?php echo @$output; ?></b></font></td>
    </tr>
    <tr> 
      <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Messaggio:</font></td>
      <td> 
        <textarea name="message" rows="5" cols="40" wrap="virtual"></textarea>
      </td>
    </tr>
    <tr> 
      <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Destinatario:</font></td>
      <td>
        <textarea name="dest" cols="15"><?php $num_totale_di_numeri=count($numeri); //trovo il numero totale dei numeri

For ($n=0; $n<$num_totale_di_numeri; $n++) {

echo $numeri[$n];

}   ?></textarea>
      </td>
    </tr>
    <tr> 
      <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Mittente:</font></td>
      <td> 
        <input type="text" name="sender" size="10">
      </td>
    </tr>   
    <tr> 
      <td colspan=2> 
        <div align="center"> 
          <input type="submit" value="Invia">
        </div>
      </td>
    </tr>
  </form>
</table>
<div align="center"></div>
<?php
mysql_free_result($Rs_telefono);
?>
 
Scusate se riapro il post...

gentilmente se volessi avere sempre presente, il credito residuo, e poter scegliere quanti sms voglio inviare, tipo pacchetti da 10, 20, ecc.. come posso integrarlo in questo script? grazie e scusate la riapertura.
 
ciao
sarebbe meglio un altro post (un problema => un post) comunque (dovrei sapere meglio come è il tuo db) ma da quello che ho capito un tuo iscritto può "acquistare" un pacchetto di 10, 20,.... sms. qquindi all'atto dell'acquisto metti tale valore nel db in corrispondenza dell'utente e quando questi invia un sms decrementi il valore di uno e mfai in modo che se la quantità è zero non possa inviare, per vederli poi nelle astessa maniere con cui vedi gli altri dati
 

Discussioni simili