Halea
Well-Known Member
- Joined
- Aug 12, 2016
- Messages
- 1,132
- Reaction score
- 874
What's the proper way of posting long documents here? (A few hundreds of lines)
Edit: Following Ward's advice it has been attached as a tar.gz file
Once you have both the receiving and transmitting scripts in place, any incoming sms sent to you by Bulkvs is going to trigger sms-rx.php, which will extract its content and send it to your user account as an email with a judiciously formatted subject line showing up the incoming phone number etc.
Then, you can simply reply to that email with your outgoing message (without changing anything to the subject line), which will go sit in a drop box monitored by sms-tx.php.
Next, cron activated (every minute) sms-tx.php will fetch your reply email, analyze the subject line which is a Re: to the incoming message subject line (with the proper phone numbers), and if both phone numbers as well as a usable text body are available will put it in an sms format and send it out to the BulkVS gateway. - That simple.
If you want to send out an sms message without replying to a received message, simply write an email to the drop box while ensuring that the subject line contains something like SMS_FROM=12223334444&SMS_TO=12223334444
--------------------------------------------------------------------------
Edit 5/24/2020: I found out that there is a bug or rather a logic error in the way the SMS "from" and "to" addresses are handled. I fixed it
. If you're interested in getting the updated version please drop a word. The one posted here (v 1.0) is perfectly usable and I have been using it for several weeks without realizing the issue. So, what is it about?Well, I designed sms-rx.php and and sms-tx.php in such a way that the user has minimal overhead to enter during messaging.
sms-rx.php parses bulkvs' "get url" post and creates a subject line showing sms-from, sms-to and the ip address from where it got the message. The body of the email is the message portion of the post.
When the intended user receives the email from sms-rx it looks like an ordinary email message to which it can simply answer by clicking on the "reply" button of its email tool; at which time the subject line is automatically prefaced by Re: or something equivalent (determined by the email tool). The original email message also has a "Reply-To:" field initialized with the intended email drop box for the sms-tx process. Therefore, as the user clicks on reply, a preformatted email reply message is made with the same subject line and the proper return email address so that it ends up in the drop box periodically checked by sms-tx.php
Now, obviously the subject line is not adjusted for the fact that the return message still shows the original sms sender and receiver phone numbers. Since this is a reply message the phone numbers need to be swapped, and the sms-tx script does just that flawlessly (and mindlessly). There is nothing wrong up to this point.
What happens if one is not replying to an incoming message but simply creating an outgoing basic message? Well, he creates the subject line himself and assumes that SMS_FROM is the sender's phone, and SMS_TO is the receiver's phone!
Well, sms-tx.php v 1.0 script still reverses those two phone numbers without properly checking that this is not a reply message but a direct message

How should it check though? Well, the IP address used in incoming messages subject line is used as an indication that we are dealing with a return message, therefore the phone numbers need to be swapped. If there is no gateway ip field in the subject line then there is no need for swapping them.

The reason for which I didn't catch the problem until now is that I was using an email template to quickly create test messages, and once I finished testing I kept using the same template for actual sms sending, and my template had the two labels swapped.

Earlier today my system processed its 1,000th sms message!

Update 1/16/2021: I've replaced the attachment file with the latest scripts. The sms reception script remains largely the same but a script version number was added to the email message subject file format. It's quite unobtrusive.
As for the sms transmission script, it fixes the phone number swap issue, but also adds an authorization code to the direct-sent message subject line, without which anyone who can send mail to the sms gateway mailbox could use the gateway.
The attached file contains both the reception and transmission scripts. You need to extract the php blocks as mentioned in the comments and create 2 separate php files, one for reception, one for transmission. I call them sms-rx.php and sms-tx.php but you can call them as you wish.
sms-rx.php needs to be put in the root of your web server. If you want to run it on your PBX it will be under /var/www.html. For my home use I do run it on my PBX too, the impact on performance is absolutely negligible. It's invoked every time when there is a new sms message that BulkVS wants to deliver to your system.
sms-tx.php could be run from any location as long as the proper php material is available (see the comments in the attachment file). I also run it on my home PBX. sms-tx.php needs to be triggered every 10 to 60 seconds so that the email messages intended to be sent out as sms are processed in a timely fashion. cron is my favorite way of triggering it, but other ways are possible, like with a watch command, or in a bash loop. This script checks an email box dedicated to sms messages. It scans through once per execution. If it finds a message (or more) with the proper format it processes it. If malformed or unrelated messages are found (like spam) they are simply deleted. The goal of this approach is to keep that email box as light as possible so that every time it's scanned the script doesn't have to go through tons of non-sms material which would slow it down significantly. So, under normal use conditions the mail box is close to empty.
Update 8/30/2021 : SMS reception has been enhanced with SMS forwarding to another phone number in a new script called sms-rx-jef.php. It can be found here.
Attachments
Last edited: