receive mails through php

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi ! All,

I want to write one php script which can accept any mail send to my
mail id. Can any one help me out in this.


Re: receive mails through php

Aditi Jindal wrote:
Quoted text here. Click to load it

What have you tried so far?
Have any code?
What experience do you have with PHP?

You may find someone to tell you how to do it, but I don't think it will
be free.

Remove the "x" from my email address
Scott Johnson

Re: receive mails through php

Quoted text here. Click to load it

If you are running a UNIX (or similar, such as Linux) system with
its own mail transport agent like Sendmail or Exim, you can use a
".forward" file in your home directory to specify that the message
should be piped into a command that you specify (which could be a
PHP script).  For safety until it is debugged, I recommend directing
the mail to a file *and* the command, so when the first try blows
up, you don't lose mail.  You can also set up an alias which receives
mail by piping it into a command.

Now search "command line" in the online documentation on
It's possible that the command-line PHP isn't installed on your
system even if PHP and a web server are.  There's a few differences
between command-line PHP and web server PHP.  There are no $_GET,
$_POST, $_REQUEST, $_COOKIE, etc., but there are $argc and $argv[].
The email will be available on the predefined file handle STDIN.

Re: receive mails through php

On 20 Apr, 06:33, (Gordon Burditt) wrote:
Quoted text here. Click to load it

Most Linux distros come with MTAs configured to use procmail as the
delivery agent. Procmail allows you to do lots different things - its
a programming language all of its own.

e.g. you could set up a recipe which:

1) checks 'from' addresses in incoming mail and automatically rejects
any not in a white list
2) forward all messages with 'PHP' in the subject to a different
3) passes the remainder to a virus scanning pipe
4) automatically responds to any messages still in progress
5) send a copy of any message addressed to '' to a
script, and a copy to your normal mailbox
6) filter any remaining messages through a different script
7) ....?

If you can't setup .forward or .procmailrc on your system then you'll
have to pool the message via imap or pop.


Re: receive mails through php

Aditi Jindal wrote:
Quoted text here. Click to load it

I guess my first question is - what problem are you trying to solve?
There are any number of ways to do what you want.  But how to go about
it depends on what you're trying to accomplish.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: receive mails through php


on 04/20/2009 01:45 AM Aditi Jindal said the following:
Quoted text here. Click to load it

If you have a POP3 mailbox associated to your e-mail address you can use
a POP3 client to list, retrieve and delete messages from your mailbox in
PHP. That is a solution that works regardless of the type of platform
that runs PHP . In that case you may want to try this POP3 client class:

You can also attach a PHP script to a mail server to process incoming
messages, but that depends on the mail server.

You may also want to ready this article that explains the details and
pros & cons of each approach:


Manuel Lemos

Find and post PHP jobs /

PHP Classes - Free ready to use OOP components written in PHP /

Site Timeline