Here's a challenging one - having a PHP-based website accept incoming E-mail
Various bulkmail related subjects have been discussed here, but none address the problem that my client has dropped into my lap this morning. So here goes. :-)
It is fairly routine to have a chunk of PHP-based website code send out an E-mail message (HTML-formatted or otherwise) to each recipient in a list (either retrieved from a mySQL table, a flat file, or whatever) and handle all related tasks.
What I am looking for, though, is a way to have a website forward an incoming e-mail to all recipients on a distribution list - have the PHP website act as a mailing list engine, in other words.
Authentication and control could be done on the basis of passwords in the subject line, various custom header fields, and what not. That's not the hard part.
The hard part (and the central question in this post) is how to get the e-mail into the website? My client would like to create an e-mail message using their standard e-mail applications (be it Outlook, Gmail or whatever) and "send that e-mail to the website" (to use their words) which must then take care of further distribution.
So... how am I going to "send an email to the website"? Which will of course typically be hosted in a shared hosting environment, so we won't have access to the server in order to set up facilities that deal with incoming e-mail, a mail server or something similar.
Having a PHP-based chunk of website code accept an incoming POP3 (or IMAP) session would be the key to solving this particular puzzle, I believe. MX records etc. to get it to the server would be dealt with at the DNS level, which is solvable...
But how am I going to make the website accept incoming E-mail? Can this be done at all? And if so, how?
Maybe I could open a socket that listens on a given port for incoming connections? (There would be firewalling issues to be discussed with the hosting provider, of course.) If it is impossible to directly accept incoming e-mail, a second option (as a work-around) could be to send the "incoming" e-mail to a dedicated external mailbox, and have the website poll this periodically to collect it... But that creates a new problem in how to do schedule this, without access to cron. I know how to fork off a child process that then continues to run as a daemon in the background, so presumably I could do this on the first page load and then have each subsequent page load check for the presence of the daemon process in the background, but this does seem a rather convoluted and problem-prone approach to me... not to mention the fact that the long-term survival of the daemon process is not guaranteed, given the fact that I know nothing about what goes on at the server OS level. But it's either that, or add another step to the process flow: create the e-mail, send it off to the dedicated e-mail address, and then (after allowing time for delivery) start the fetch-and-distribute cycle manually via a form on the website... which I find less elegant, not to mention more cumbersome (and therefore error-prone) to the typical secretarial employee who will most likely be charged with this job.
Anyway. Food for headaches - in plenty! :-)
All suggestions, hints, pointers and donations of aspirin will be greatly appreciated!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread