Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any simple text-based mail client that I could use that could trigger a PHP script to parse mails received from the users?

I have a PHP application that sends email out to users and it would be nice if the application can parse the reply from users and store them into the database.

I'm using Centos 6 with Postfix and PHP sends email out using PHPMailer. No X Window System installed.

share|improve this question
You may want to migrate this to stackoverflow.com, as it is more programming than unix/linux oriented. – peterph Jun 27 '13 at 9:02
I'm not really sure about the OS but what I would like to do is have a mail client to trigger a PHP script that will parse email reply whenever it receive mail. Or is there a better way of doing it? – John Doe Jun 27 '13 at 10:48
up vote 1 down vote accepted

Your question is a bit confusing, as you refer to a text-based mail client and a PHP application and then specify that "the application" (i.e. your PHP application) to store email (or data extracted from that) in a database.

You can and probably should separate your sending application from your response processing application. The response processing can be done by calling any script from procmail, for that you need a .procmailrc file in the home directory of the receiving user that has the following:

* ^Subject:.*[response-email]
| /path/to/your_script

You can leave out the Subject line if you want all mails to that email address processed, or use different selection criteria.

As for your_script I don't know of any commandline mail clients that directly put your material in a database. Since you probably should test the response anyway (if not to extract some extra database fields, at least to throw away spam) you might want to write your_script in PHP using PECL to parse its content and store it in your database. (Of course you can use other languages you are familiar with for this purpose as well).

If you are using postfix to receive emails on the machine this script runs on, make sure to call procmail in /etc/postfix/main.cf:

mailbox_command = procmail -a "$EXTENSION"
share|improve this answer
Hi anthon, I'm not sure how Centos works but I'm looking for a mail client that could trigger a PHP script that could trigger a PHP script to parse email reply whenever a mail is received. Can this be done in Linux? Sorry for the terrible English. I think it's confusing myself. – John Doe Jun 27 '13 at 10:52
Youd don't need a mail client for that. Either your CentOS system receives the mail directly, or you pick it up via fetchmail and forward it to the user with the .procmailrc (I do exactly that on my workstation). procmail will trigger your PHP script. – Anthon Jun 27 '13 at 10:55
If you want to use literal square brackets in a regex, you have to backslash-escape them -- \[response-email\] – tripleee Jun 27 '13 at 12:48

I didn't get if you want to parse it in your PHP-application or just on the server. Both variants are possible without using any mail-client.

1) Bash/SH or another scripting language. Something like that:



for mFile in `grep -iR 'WHAT TO FIND???' .`
  # here do something with your e-mail z.B:
  mysql -u $MyUSER -h $MyHOST -p$MyPASS MyDB << EOF
      insert into ...
      values ...;

2) Or parser on the application side (in PHP), which is pretty simple. Have a look at this library: https://github.com/plancake/official-library-php-email-parser

share|improve this answer
But without a mail client, how would I be able to receive mail files? – John Doe Jun 27 '13 at 10:44
Postfix server is responsible for that. Look at link, in case you havn't configured it yet. – Ilya Ananyev Jun 27 '13 at 10:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.