Dealing with Bounced Email

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

Threaded View
I've written a simple e-newsletter app using the PHP mail() command.

I want to be able to deal with bounce-backs if a member's email is no
longer working or is using an old account. I'm using a Red Hat Linux
server with Sendmail and Apache. I've seen mention of using Procmail or
filtering mail to a certain account through a PHP script, but, can't
find detailed instructions on how this is done.

Can anyone let me know or point me toward a site that explains how to
handle bounced-back email using Sendmail and a PHP script?


Re: Dealing with Bounced Email

Monty wrote:
Quoted text here. Click to load it

Try this:

mail($To,$Subject,$Msg,$headers, '-f'.$returnaddress);

where $returnaddress = your email.


- Nicolaas

Re: Dealing with Bounced Email

Quoted text here. Click to load it

this would not help as the action is not automated...   try setting up
an account that will be monitored by a script:
On receving mail,  remove sender's adress from database,  also search
body for e-mail adresses and remove them.

Re: Dealing with Bounced Email wrote:
Quoted text here. Click to load it

It sounds like you have a mailing list and you are trying to automate the  
remove response.

It is easier to let people go to a specific page to remove.

 click on the link to remove

then remove.php:


if ( client_id_exists($client) ) {
 if ( remove_client_from_database($client) ) {;
  echo "thank you for taking the time.  your address has been removed";

function remove_client_from_database {


Re: Dealing with Bounced Email

windandwaves wrote:
Quoted text here. Click to load it

No, what I want to do is deal with the bounce-backs after sending a
broadcast email -- email that is returned because the email address is
no longer active or valid. I want to set up a PHP script to
automatically detect the returned email message, grab the email address
from the bounced back email, then remove that email from the database.

Specifically, I'm not sure how to go about using a PHP script with
Sendmail to lift the TO: email address from a bounced back email when
it is returned to the email account i have set up as the Return Path.

Re: Dealing with Bounced Email

Quoted text here. Click to load it

man procmail

Met vriendelijke groeten,
Tim Van Wassenhove <

Re: Dealing with Bounced Email wrote:
Quoted text here. Click to load it

Okay, but, how does one set up a PHP script to monitor bounced email
coming back to the account I've already set up? That's the part I have
no idea how to do.

Re: Dealing with Bounced Email

Quoted text here. Click to load it

There are several approaches:

(1) If you have a system which supports it (e.g. Linux or UNIX using
sendmail, smail, Exim, etc.), you can forward mail received by a
user into a pipe by specifying this in a .forward file in the user's
home directory.  The program (which could be written in just about
anything:  standalone PHP, Perl, sh, C, or whatever) will be invoked
with the email text (including the headers) on stdin.  Details of
what user the program will run as or what the current working
directory will be may vary.  Whether or not the admin has turned
this off or not may vary also.  It is up to the program to go
through the headers and body to figure out what to do with it.

(2) You could set up a cron job which periodically invokes a program
which polls a mailbox using POP3, IMAP, or just opens the mailbox
file directly.  For example, fetchmail can be used to transfer the
mailbox contents to a local file.  Then a program could look at
what came in.  The host with the program doesn't have to be the same
host as the one with the mailbox, in the case of POP3 or IMAP polling.

                        Gordon L. Burditt

Site Timeline