Email forward to PHP script always bounces

I am trying to execute a PHP script when an email is received on a managed server, and I only have access through cPanel.

Following this instructions I was able to get the script to work, but it still bounces the content of the email back to the sender.

I tried to read the stdin as suggested by this post, but nothing changed. Adding a $emailtext = mailRead(); does read the stdin, and adding echo $emailtext; it writes the email text in the bounced email (so I get the text twice, one from my echo and once at the end of the bounced email.)

The bounce is sent by Mail Delivery System <>, here is the content (in bold italic the parts that I changed):

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:

pipe to |/path/to/php/script generated by

The following text was generated during the delivery attempt:

------ pipe to |/path/to/php/script generated by ------

X-Powered-By: PHP/5.2.17 Content-type: text/html

here is see any output echo-ed by the script

------ This is a copy of the message, including all the headers. ------

Return-path: ...

How do I get rid of that bounce email?


Add a -q at the end of the shebang.

Here are the steps that finally gave me a working script:

  1. In cPanel create an email forwarder to a script file
  2. Make sure that the script file does not contain /n/l, but only /n (no Windows new lines in Linux)
  3. Make sure that the script starts with the correct shebang: #!/usr/bin/php -q
  4. Set the script permission to executable

Removing the -q at the end of the shebang causes the email to bounce back to the sender. Any text echo-ed by the php script is included, and it can be useful for debugging.

Points 2 and 3 made me waste hours. I spent time also trying to read the stdin and trying different exit values: the stdin doesn't need to be read as explained here, the script doesn't need to exit(0) or any exit at all.

Of course this worked for me, and may not work with different configurations. But here is my answer, hoping that it will help someone else.

Need Your Help

Jquery mobile is blocking downloading from my django based site

jquery django jquery-mobile django-templates django-views

I have a download link on my site (Django based), that worked fine until I started using jQuery-mobile. Now when I attempt hit the download link the jQuery-mobile loading screen appears and hangs

Is there a way to “tag”,“flag” or to “label” a folder on the eclipse navigator panel?

eclipse productivity tagging

I was thinking if there's a way to tag a folder on eclipse with a color, kinda like if you were using a highlighter pen. I have many folders on a project but i use 3 of them more constantly then i ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.