SMS Server Tools 3
This site is hosted by Kekekasvi.com
 Menu
Basic information:
Additional information:
Support:
Get SMS Server Tools 3:
Additional Options

 Sponsored links

 Search
Custom Search

 Visitor locations
 
 SMS Server Tools 3 Community
Welcome, Guest. Please login or register. Fri Nov 24, 2017 22:04
SMSTools3 Community » Sample scripts / setups Bottom

Multiple recipients in single SMS file

  This topic is locked

Page:  1

Author Post
Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Well, this sample script might be useful for somebody. ;)

Message format is:

To: one recipient
To: another recipient
To: Etc. ( number of To: headers is not limited. )
Other_headers: if necessary

Text body.


#!/bin/bash

# Sample script to allow multiple recipients in one message file.
# Define this script as a checkhandler.

outgoing="/var/spool/sms/outgoing"

recipients=`formail -zx "To:" < "$1"`

#count=`echo "$recipients" | wc -l`
count=`echo "$recipients" | wc -w`
if [ $count -gt 1 ]; then

  # Will need echo which accepts -n argument:
  ECHO=echo
  case `uname` in
    SunOS)
      ECHO=/usr/ucb/echo
      ;;
  esac

  messagebody=`sed -e '1,/^$/ d' < "$1"`
  headers=`formail -X "" -I "To:" -f < "$1"`

  for recipient in $recipients
  do
    file=`mktemp $outgoing/send_XXXXXX`
    $ECHO "To: $recipient" > $file
    if [ "x$headers" != "x" ]; then
      $ECHO "$headers" >> $file
    fi
    $ECHO "" >> $file
    $ECHO -n "$messagebody" >> $file
  done

  # Remove processed file:
  rm $1

  # Tell to smsd that checkhandler has spooled this message:
  exit 2
fi

exit 0
 
'bash' Syntax Highlight powered by GeSHi


EDIT: After changing wc -l to wc -w, the script allows multiple numbers in To: field (separated with spaces) and also multiple To: fields as before:

To: 358400111111 358400222222 358400333333
To: 358400444444
To: Etc. ( number of To: headers is not limited. )
Other_headers: if necessary

Text body.



« Last edit by keke on Mon Dec 13, 2010 11:34, 84 months ago. »
Member
Registered:
Jul 2009
Location: NCR, Philippines
Thanks Keke!

By the way, do you have a PHP format for multiple recipients too?

Thanks and more power!!!

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Topic owner
maboo23 wrote
By the way, do you have a PHP format for multiple recipients too?

..for handling recipients without checkhandler?

Something like this: web_sendsms.php?To=35840571XXXX, 35840571YYYY, 35840571ZZZZ&Message=This is a test.

Because PHP URL cannot have more than one similar argument name (without tricks), recipients are delimited using comma. Also note that & character cannot be included in the text, use %26 instead.

<?php

$single_file = false;

$application = "web_sendsms";
$outgoing = "/var/spool/sms/outgoing";
$error = 0;

if (empty($_GET['To']) || empty($_GET['Message']))
  $error = 1;
else
{
  $dests = split(',', $_GET['To']);
  $message = $_GET['Message'];

  if ($single_file)
  {
    $filename = $outgoing ."/". $application ."-" .str_replace(".", "", uniqid(mt_rand(), true));
    if (($handle = fopen($filename .".LOCK", "w")) != false)
    {
      foreach ($dests as $dest)
        fwrite($handle, "To: " .trim($dest) ."\n");

      fwrite($handle, "\n");
      fwrite($handle, $message);
      fclose($handle);

      if (rename($filename .".LOCK", $filename) != true)
        $error = 3;
    }
    else
      $error = 2;
  }
  else
  {
    foreach ($dests as $dest)
    {
      $filename = $outgoing ."/". $application ."-" .str_replace(".", "", uniqid(mt_rand(), true));
      if (($handle = fopen($filename .".LOCK", "w")) != false)
      {
        fwrite($handle, "To: " .trim($dest) ."\n");
        fwrite($handle, "\n");
        fwrite($handle, $message);
        fclose($handle);

        if (rename($filename .".LOCK", $filename) != true)
        {
          $error = 3;
          break;
        }
      }
      else
      {
        $error = 2;
        break;
      }
    }
  }
}

if (!$error)
  print "OK.";
else
  print "ERROR " .$error .".";
?>
 
 
'php' Syntax Highlight powered by GeSHi


EDIT: Changed random filename.


« Last edit by keke on Tue Dec 14, 2010 12:46, 84 months ago. »
Member
Registered:
Jul 2009
Location: NCR, Philippines
Thanks! but i am getting ERROR1.

Do i need to have the script before the web_sendsms.php?

Thanks Ke!

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Topic owner
maboo23 wrote
Thanks! but i am getting ERROR1.

Either To or Message argument is empty. If you called your script using wget, notice that & (before Message) should be escaped (\&Message=...). First try using a browser, for example:

.../web_sendsms.php?To=WILLFAIL&Message=Test.

This message is not sent but from the smsd log you can see if it's handled.

Quote
Do i need to have the script before the web_sendsms.php?

Sorry, I did not understand this question... :(

Member
Registered:
Jul 2009
Location: NCR, Philippines
Moved to a new topic (PHP script is not creating a file)
Hi,

Here is my php file. Its not creating a file.
Please help

...


  This topic is locked

Page:  1

SMSTools3 Community » Sample scripts / setups Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.