How to send different sms messages to multiple recipients - php

i have a somewhat challenging task.I have to write an application with PHP and MYSQL
This application is intended to be an sms application that sends sms(text messages) to
various job supervisors,reporting the messages that their subordinates have received.
The application is meant to have a template;
E.g :Message From Postmaster:
Message From Auditor:
etc.
The messages for each subordinate are stored in a table and are retrieved
for each subordinate for a given time period.Each subordinate has a job role which defines the kind of message he receives.
That is:A postman has "pre-defined" people that can send a message.E.g The Postmaster,the Post-office....etc.
An example showing the message format is:
Message From Auditor:Bring Receipts To General Office Sent On Monday
Message From Postmaster:Bring Stamps To Secretariat Sent On Monday
Message From Security: Bring Details For Id Card Sent On Tuesday
Message From Admin:
Message From Supply:
Two subordinates with the same job role can have different messages from the same person.
E.g: Employee x who is a postman might receive "Report to General Office" from the Postmaster,
while Employee y might receive the message "Add New Delivery Routes From Next Week"
The phone numbers for the Supervisors are stored in a table.
A supervisor can supervise multiple people
who have different job roles.
The major point where i will need assistance
is on how to program the application to pick the phone number of the supervisor for each
employee,get the templates for the employee's job role,and populate it with the messages
for the employee and send it to the supervisor.Also, the employees can have more than 1 supervisor.
I know i will need a loop(a "for-each" loop ??)..
I am not also very knowledgeable about the procedure used in sending sms messages to people
from a website with php,
but i know it has to do with arrays.
So in short...i need help on building arrays that will house the phone numbers,message-template
and message template for a particular job role with individual messages
and loop through them
and send them to the recipients.
I will really appreciate any help i can get and i will gladly supply my email to interested parties to further correspondence.THANKS

It sounds like you need to learn some more PHP/MySQL before you'll be able to tackle this... The major part you need help with is straightforward, just some tables and queries... For the SMS, Google for "PHP SMS API" and you will find scads of options.
I am not also very knowledgeable about the procedure used in sending
sms messages to people from a website with php, but i know it has to
do with arrays
No this is not true. Arrays may be used to implement portions of the code used in doing so, but that statement is like saying building a website w/ PHP has to do w/ arrays... You might try the php-general mailing list for more help getting off the ground in your PHP coding, but there really isn't a specific question here.

Related

Database structure for Web Messaging system (for both registered users and guests)

I'm trying to create a very simple messaging system using PHP and MySQL but I'm having some issues to decide how to structure things here.
A quick list of what I need to achieve.
The system needs to allow both registered users and guests send messages.
The messages will be received by the customer service department (this means that customers can't send messages to other customers).
The messages can come from 1) a contact form available in the Contact page of the website where are asked fist name, last name, email, mobile phone, subject and message; and 2) emails sent by users (then the system will receive the emails via webhook and store them properly).
The customer service department needs to able to reply to any message.
The customer service department can contact any user (registered or not) at any time. This means that they can reply to messages but also can "start" the conversation (example: A message asking to confirm/update details).
I started the design but I'm completely stuck at the moment. Everything is fine when there are only registered users and customer service members: I just need to relate each message to a user_id as sender or receiver. But, when we add guest users, the user_id is useless, because they are not registered (so no user id). This means I will need to store all first name, last name, email and mobile phone for them (creating redundant data in the case of registered users, because I already have that data for them)
The tables will contain a column created_at.
My problem is: guest users won't have a record in the users table, so I cannot just have a user_id field on the messages tables. Also, I need to tell who is sending the message (because our customer service department can send messages to registered/guest users).
Honestly I cannot find a way to achieve this without having columns that will be equal to null in most of the cases.
Any help on this will be appreciated.
Thanks in advance
You will need to have a record added for the guest, as a user account in the database. Set default values, and log his IP address so should he decide to sign up, you will update the guest record with the new user account.
Add an expiry and a cron job to delete any guest accounts which are inactive for x days.
You have encountered an example where the relational model doesn't neatly fit. It's a known issue, with several Stack Overflow posts.
The good news is - there's no "clean" solution in database design. There are a few common models, but they all have varying degrees of unpleasantness.
The bad news - you'll have to make the trade-offs, and live with the consequences.

Best way to store Gmail conversations in MySQL from the Google API (Indexes)

For those that have built an app using Gmail's API, I'd love to get your feedback on database structure for conversations.
Currently, my app looks at email addresses in my own DB and uses the listmesssagesfunction to grab ids and then finds user_messagesbased on those ids.
Basically, it's looking to see if there were previous interactions with a specific contact.
I'd like to run this script in a cron job, but I'm having a difficult time deciding how to index these to avoid duplication.
The fields that I'm storing in MySQL from the Gmail API are:
messageid
thread id
from name
to name
subject
email date
mime type
body
I'd like to be able to periodically check (24 hours) to see if there were responses in the Gmail account until a project is marked as "complete."
Any ideas on how to index these to avoid duplication?

Get all SMS from a particular number in inbox - Esendex

I am using the Esendex Rest API http://developers.esendex.com/APIs/REST-API/inbox and I am trying to get all the messages in the inbox from a particular phone number.
This is basically so if I do a send out of SMS's and someone replies I am able to retrieve the reply.
I can currently get all the messages in the inbox into an array and sort them, but this is too slow with over 4000 messages.
Does anyone know if I can filter by phone number, or at least date-received in my API requests? Even if I could get the last weeks worth of SMS's.
You can try to use the conversation API if you want to filter by a phone number. The drawback is that you can get only the latest 15 messages, also that there is no reliable way to detect if a reply has been received from a phone number other than the inbox API. Apart from this I wasn't able to find anything that can help you. Their API is very restrictive and minimal.
There's currently no way to do this via the REST API but I'll see if we can add it over the next couple of weeks (I work for Esendex). As you note the functionality already exists in the Conversations API albeit in a more minimal form.
In the meantime you could achieve this by checking all messages that arrive either by polling the Inbox or using Push Notifications.

PHP / MySQL Ticket Response - Store E-mail repsonse in database?

I am building a basic support request system where the customer can log in and ask a question and an admin can go in and reply and it will set the status to "Responded" and e-mail the customer to let them know someone has responded.
My question is.. I have a "comments" section which is a log of the interaction between the admin and the customer. If I e-mail the customer the initial response from the admin, then I have a feeling they will just hit "Reply" from their email and start communicating through there, and the logs won't be stored.
I could either e-mail the customer and say "Log in to view the response", or maybe if the customer does hit reply I can somehow track it and insert that in the comments table like they did it from the website. If that is even possible?
Just wondering if there is a standard way to do this and any suggestions you may have.
Thanks!
When sending the email to the user you can have it sent from an email address created for that specific ticket. Something that can identify it with your email system to help you route it back to the php ticketing system.
support(ticketnumber)#domain
support12345#mydomain.com
Then it depends on your email server how to go from there.
There are several useful tips at this question that may help or get your started.
How to get email and their attachments from PHP
If you want their reply to be automatically inserted into the DB, you'll have a assign a cron job in your server to run a php script to detect whether there's a reply from a customer (you need a table listing the customers' email and names.
Each time a customer uses the ticket system their email and name goes into this table).
You'll need to connect to your Inbox too via imap or SMTP, and there are scripts to do this (phpmailer, swiftmailer, etc) and "walk" through each email and see if the sender email matches any in your customers table. Then so an INSERT to the comments table.
Anther way is to read through the emails each time the comments page is loaded, but this will cause the page to take longer to load. However, the data will always be more "real-time" compared to cron jobs.
You could use email piping (if your server supports it).
In the subject, you'd have a unique identifier which contains the ticket ID or something unique to the ticket. Example: "How do I eat food [Question: #1234]", where 1234 is the ticket ID.
In your control panel, you would set up an email forwarder to your email piping script.
This tutorial offers the basics to email piping, and I used it as the base for my piping script: http://www.damnsemicolon.com/php/parse-emails-in-php-with-email-piping-part-1

How shall I setup user event notifications in my code?

I'm coding a team collaboration web app in PHP, and I have a few events that users get notified about through email and/or SMS. The current way I'm doing it is as follows:
Every user has his notification settings in the database as boolean variables.
Say users would be notified when someone comments on the team's page. When the function that posts a comment is called, the same function would contain extra code that checks "who wants to be notified about this?" and then sends notifications to them (which slows down the function a bit).
Is there a more efficient/faster/flexible way to setup notifications? maybe through a script that runs via a cron job? or shall I just keep doing it this way?
I appreciate your help.
I implemented a similar method to the one you're following on a website with a multi-table approach. The users table held the contact information along with opt-in, opt-out options while an event table held the instructions to notify. Several other events were hard coded because of their importance. The thing that set the site apart a bit was a "workflow" area on the user's dashboard that also showed the user what action items they had. We found that most users ignored the emails and dealt directly with that dashboard workflow area. You'd be surprised how many times people change emails or just ignore them altogether.
With 280,000 users and daily visits in the tens of thousands, there was no performance issue noticed. However, the process of queuing emails can be inefficient if you're not careful, so take particular time to benchmark your mail sending functions--its as easy as echoing out microtime before and after the mail send is accomplished--to evaluate its effectiveness. On my current company's site, such improvements yielded a 800% reduction of email queuing time (queuing being the process of generating the emails and submitting them via php mailer to the mail system for distribution)
I'd say have a table that is a queue of notifications. Let the function that post a comment still check "who wants to be notified about this?" but then just log entries containing the messages in this table. Then have a separate process work from the queue i.e. your cron job suggestion.
Depending on your database you may perhaps make use of database events or triggers instead of a cron job. This however have the requirement that your database allow you to put code in your database that will send the SMS or Email. This poses a security risk normally which you may or may not be concerned about in your setup.

Categories