Forum Moderators: coopster

Message Too Old, No Replies

PHP and email

         

hermes

3:18 pm on Jan 8, 2005 (gmt 0)

10+ Year Member



I would be so grateful if anyone can help me with this problem. I know that PHP can be used to send emails. But I want PHP to read emails!

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.

jshpro2

5:13 pm on Jan 8, 2005 (gmt 0)

10+ Year Member



resource imap_open ( string mailbox, string username, string password [, int options])

Although the imap functions are designed for imap servers, there is pop3 support

As for pattern recognition try out preg_match_all

hermes

2:08 pm on Jan 9, 2005 (gmt 0)

10+ Year Member



What I want to do exactly is: I receive an email from someone. In the message body of this email there is an email address listed.

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

[emailsoftwaretools.com...]

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.

hermes

2:13 pm on Jan 9, 2005 (gmt 0)

10+ Year Member



MY QUESTIONS:

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.

jshpro2

10:32 pm on Jan 9, 2005 (gmt 0)

10+ Year Member



What I would do is set up a cron job to run checkmail.php every 5 minutes,
then in checkmail.php use the imap functions to check for new mail, if so parse it, else, exit.
5-10 minutes is what I'd recommend, not too often to waste server resources, not to slow either.

It's all really up to you, my solution is just one possible way, expirement with different ways, see which works best for you.