views:

72

answers:

2

I get poorly formatted invoice related email from my payment gateway. I wan to automatically format these emails to make them more readbale. Mostly I want to remove few 'fixed' lines which are always present in email body.

  1. Do I need to run some sort of PHP process to do it?
  2. Is it possible to do it on email server itself?

EDIT

I have got cpanel access only.

A: 

Have your email program pipe the email to a PHP script (if you use cpanel it makes this very easy to do). Then use your PHP script to parse the email and reformat it however you see fit.

Edit

Now that we know you use cPanel here are some instructions:

1) On your cpanel main page click on the forwarders icon/link

2) Click on the "Add Forwarder" button

3) Under "Address" enter the email address that receives the emails you wish to process

4) Under "Destination" choose "Pipe to a Program:"

5) Enter the full path the the script that processes the email

6) Click on the "Add Forwarder" button to create the forwarder

This tutorial may be helpful in showing you how to process the email when it arrives at your script.

John Conde
@John Conde: Is it possible to pipe emails to PHP scripts selectively? I mean, instead off piping all emails, could I only pipe emails from one particular id.
understack
I would have the emails not only hit your inbox but also forward to another address which pipes to your PHP script. Then you can selectively choose which emails to process and which ones to ignore.
John Conde
@understack - it's possible with procmail. See my answer :)
DVK
@John - your answer is kind of not covering the most important detail (just HOW to achieve the "email program pipe the email" step)
Lemurik
Now that they confirmed they use cpanel I have added instructions for piping to a php script.
John Conde
A: 

Depends on what your email server is.

In the elder days, you used to do this with a procmail mail filter (or better yet use procmail as MDA - mail delivery agent - on your Unix host), and then have the procmail rule which would run each matching email through a Perl script which re-formats them (easy to do in Perl) and forwards them on (you can probably use PHP if you know that but not Perl, but Perl excels at text crunching, obviously).

UPDATE: You said that you have cPanel access - you can google for how to configure procmail via cPanel. I saw 2 promising links: this and this

DVK