1 |
torben |
2125 |
<?php |
2 |
|
|
require_once("mysql.php"); |
3 |
|
|
|
4 |
|
|
function sendmessages() { |
5 |
|
|
$sql = "select id,receiver,message from outbox where status='NEW'"; |
6 |
|
|
|
7 |
|
|
$rows = query($sql); |
8 |
|
|
|
9 |
|
|
foreach($rows as $row) { |
10 |
|
|
$id = $row->id; |
11 |
|
|
|
12 |
|
|
$sms = ""; |
13 |
|
|
$sms .= "To: {$row->receiver}\n"; |
14 |
|
|
$sms .= "\n"; |
15 |
|
|
$sms .= $row->message; |
16 |
|
|
|
17 |
|
|
$file = "smsout_{$id}"; |
18 |
|
|
|
19 |
|
|
$tmpnam = "/tmp/$file"; |
20 |
|
|
|
21 |
|
|
file_put_contents($tmpnam, $sms); |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
$target = "/var/spool/sms/outgoing/$file"; |
25 |
|
|
rename($tmpnam, $target) or die("error renaming $tmpnam $target"); |
26 |
|
|
|
27 |
|
|
$sql = "update outbox set status='TRANSMITTING', statustime=now() where id=$id"; |
28 |
|
|
squery($sql); |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
} //end function |