Forum Moderators: coopster
That is, with an email received, I want PHP to look inside the email and perform pattern recognition. I want it to look for a certain string in the email message body.
How can this be done?
N.B we are dealing with an e-mail account on a server. PHP being installed on this server as well.
Thank you ever so much.
I want to autoreply. But the twist is that I do not want to autoreply to the someone that sent me the email. But to the email address listed in the message body.
So, what I guess I will have to do: open each incoming email. Look for an email addresses in the message body. If one is found then send a message to it.
I want to automatically send the autoreply email as soon as possible after the incoming email.
So, what are my choices. From my research thus far.
1) I can pipe incoming emails to a script that parses them.
Advantage: very fast.
Disadvantage: may have problems getting a server to support this. It requires PHP compiled as a CGI binary,
not just as an Apache module.
Really good tutorial on this:
[gvtulder.f2o.org...]
2) I can use IMAP functions.
3) Net_POP3
POP3 PEAR class. Note that it also needs the Net_Socket class.
[pear.php.net...]
[pear.php.net...]
USEFUL FUNCTION:
Net_POP3::getMsg() -- Returns the entire message
4) MAILPARSE
Is not in the main PHP release (yet at least)
Mailparse is an extension for parsing and working with email messages.
Can download it here at PECL
PECL is a repository for PHP Extensions.
[pecl.php.net...]
The mailparse extension can be used to break apart MIME compliant email messages, so it is useful for people implementing
web mail in an environment where more traditional methods such as using the IMAP c-client library are not possible. Also,
it is designed to use very little resources while dealing with the messages, so you wont find that your server gets
hammered when someone sends or reads that email with 10MB of attachments.
5) POP3 polling
If your hosting provider does not support email piping, you may use an alternate technique - pop3 account polling.
The idea is pretty simple: poll an external POP3 account on a regular basis, retrieve email messages (if any),
execute an email processing program and feed the message text to the program's standard input.
The Perl script, which may be executed both on Windows and UNIX servers is available from CGI-Research, a division of
Eastwright Corporation and may be downloaded for a rather nominal $4.95 fee.
1) Does anyone know of a method of email piping that does not require the server to be set up in an obscure manner that will cause issues when one comes to hosting?
2) For IMAP functions in PHP: how do I set up the time interval for how often the IMAP function checks the mailbox? Do I perhaps use the Date and Time on the server to set some kind of frequency? Perhaps every 5 minutes? Would this be too much?
3) For IMAP functions in PHP: what percentage of hosts would one imagine can support this? Is it quite standard? Or could I run into problems with hosting?
4) Has anyone any experience with Net_POP3 or mailparse? How difficult is it to get a host that supports these?
Would be so, so grateful for any advice.
It's all really up to you, my solution is just one possible way, expirement with different ways, see which works best for you.