The Golden Rule of Developing
Don't Reinvent the Wheel
The internet has been around for a long time it is likely someone has had a need to solve the same problem you are trying to solve now.
In this case there are many Support Ticket Systems currently available, many work with PHP and databases.
One option is osTicket this can be downloaded and used completely free of charge, and includes many features including.
* Custom Fields
* Rich Text HTML
* Ticket Filters
* Auto-Responder
* Customer Portals
* Reports
* Email Piping, POP3, and IMAP functionality (osTicket uses cron jobs to check the email accounts).
If you haven't already had a look at it might be able to solve your problems and save you some time.
Invent Your Own Wheel
Keep in mind that email can be treated like any other form of standard input.
PHP IMAP Functions
The commands to use IMAP in PHP are imap_open
to connect and imap_search
to obtain the emails. The PHP Manual steps through all of the available functions, and syntax in their IMAP Book
Check Email Functions
If using IMAP functions you would need a method to periodically check your email account for new mail, An inefficient way to do this has previously been shown on StackOverflow Question 11766165. You could also use an AJAX
function, cron
job, or Windows Task Scheduler
(there would be many other ways to do this).
I understand that to mean you want to use Ajax for the purpose of initiating and re-initiating the script? You would just have to refresh the page to have the script run again. Did you know that you can run PHP scripts without a web browser? cron
or Windows Task Scheduler
will perform this task as long as their is a PHP interpreter running on the server.